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

The following examples show how to use android.widget.TimePicker#setIs24HourView() . 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: TravelTimePicker.java    From msdkui-android with Apache License 2.0 6 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity())
            .setNegativeButton(R.string.msdkui_cancel, null)
            .setPositiveButton(R.string.msdkui_ok, null);

    final View view = View.inflate(getActivity(), R.layout.travel_time_picker, null);
    dialogBuilder.setView(view);

    mTabLayout = (TabLayout) view.findViewById(R.id.picker_tab);
    mDatePicker = (DatePicker) view.findViewById(R.id.travel_date);
    mTimePicker = (TimePicker) view.findViewById(R.id.travel_time);
    mTimePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity()));

    updateDefaultValues();
    updateTab(savedInstanceState);
    updateDatePicker(savedInstanceState);
    updateTimePicker(savedInstanceState);
    updateVisibility(savedInstanceState);

    final Dialog dialog = dialogBuilder.create();
    dialog.setOnShowListener(mOnShowListener);
    return dialog;
}
 
Example 2
Source File: TimePickerPreference.java    From ploggy with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected View onCreateDialogView() {

        tp = new TimePicker(getContext());
        tp.setOnTimeChangedListener(this);

        String value = getPersistedString(this.defaultValue);
        int h = getHour(value);
        int m = getMinute(value);
        if (h >= 0 && m >= 0) {
                tp.setCurrentHour(h);
                tp.setCurrentMinute(m);
        }
        tp.setIs24HourView(DateFormat.is24HourFormat(getContext()));

        return tp;
}
 
Example 3
Source File: DialogUtil.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 时间选择对话框
 *
 * @param con      上下文
 * @param title    标题
 * @param listener 选择事件
 * @param cal      默认时间
 */
public static void pickTime(Context con, String title, Calendar cal, final OnTimeSetListener listener) {
    LinearLayout ll = new LinearLayout(con);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    ll.setLayoutParams(layoutParams);
    ll.setOrientation(LinearLayout.VERTICAL);
    //添加一条线
    LinearLayout line = new LinearLayout(con);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
    line.setBackgroundColor(con.getResources().getColor(R.color.line));
    line.setLayoutParams(lp);
    ll.addView(line);
    //添加选择器控件
    final TimePicker timePicker = new TimePicker(con, null, themeId);
    timePicker.setLayoutParams(layoutParams);
    timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(cal.get(Calendar.MINUTE));
    timePicker.setIs24HourView(true);
    ll.addView(timePicker);
    QuickDialog.Builder builder = new QuickDialog.Builder(con);
    builder.setContentView(ll);
    builder.setTitle(title);
    builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            listener.onTimeSet(timePicker, timePicker.getCurrentHour(), timePicker.getCurrentMinute());
        }
    });
    builder.create().show();
}
 
Example 4
Source File: StartNewSensor.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@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 5
Source File: TimeEventSkillViewFragment.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    timePicker = new TimePicker(getContext());
    timePicker.setIs24HourView(!SettingsUtils.use12HourClock(getContext()));

    return timePicker;
}
 
Example 6
Source File: ClockPreference.java    From heads-up with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected View onCreateDialogView() {
    int defaultValue = getKey().equals("night_mode_start") ? 1320 : 420;
    int value = getPersistedInt(defaultValue);

    mTimePicker = new TimePicker(getContext());

    mTimePicker.setCurrentHour((int) Math.floor(value / 60));
    mTimePicker.setCurrentMinute((int) Math.floor(value % 60));
    mTimePicker.setIs24HourView(DateFormat.is24HourFormat(getContext().getApplicationContext()));

    return mTimePicker;
}
 
Example 7
Source File: SimpleTimeDialog.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected View onCreateContentView(Bundle savedInstanceState) {

    picker = new TimePicker(getContext());

    if (savedInstanceState != null){
        picker.setCurrentHour(savedInstanceState.getInt(HOUR));
        picker.setCurrentMinute(savedInstanceState.getInt(MINUTE));

    } else {
        if (getArguments().containsKey(HOUR)) {
            picker.setCurrentHour(getArguments().getInt(HOUR));
        }
        if (getArguments().containsKey(MINUTE)) {
            picker.setCurrentMinute(getArguments().getInt(MINUTE));
        }
    }

    if (getArguments().containsKey(VIEW_24_HOUR)) {
        picker.setIs24HourView(getArguments().getBoolean(VIEW_24_HOUR));
    } else {
        picker.setIs24HourView(DateFormat.is24HourFormat(getContext())); // system default
    }
    picker.setOnTimeChangedListener(this);

    return picker;
}
 
Example 8
Source File: TimeSetterDialog.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initWidget(View view) {
    Button done = view.findViewById(R.id.dialog_time_setter_done);
    done.setOnClickListener(this);

    Button cancel = view.findViewById(R.id.dialog_time_setter_cancel);
    cancel.setOnClickListener(this);

    TimePicker timePicker = view.findViewById(R.id.dialog_time_setter_time_picker);
    timePicker.setIs24HourView(true);
    timePicker.setOnTimeChangedListener(this);
}
 
Example 9
Source File: DateTimePickerDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param context The context the dialog is to run in.
 * @param callBack How the parent is notified that the date is set.
 * @param year The initial year of the dialog.
 * @param monthOfYear The initial month of the dialog.
 * @param dayOfMonth The initial day of the dialog.
 */
public DateTimePickerDialog(Context context,
        OnDateTimeSetListener callBack,
        int year,
        int monthOfYear,
        int dayOfMonth,
        int hourOfDay, int minute, boolean is24HourView,
        long min, long max) {
    super(context, 0);

    mMinTimeMillis = min;
    mMaxTimeMillis = max;

    mCallBack = callBack;

    setButton(BUTTON_POSITIVE, context.getText(
            R.string.date_picker_dialog_set), this);
    setButton(BUTTON_NEGATIVE, context.getText(android.R.string.cancel),
            (OnClickListener) null);
    setIcon(0);
    setTitle(context.getText(R.string.date_time_picker_dialog_title));

    LayoutInflater inflater =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.date_time_picker_dialog, null);
    setView(view);
    mDatePicker = (DatePicker) view.findViewById(R.id.date_picker);
    DateDialogNormalizer.normalize(mDatePicker, this,
            year, monthOfYear, dayOfMonth, hourOfDay, minute, min, max);

    mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
    mTimePicker.setIs24HourView(is24HourView);
    mTimePicker.setCurrentHour(hourOfDay);
    mTimePicker.setCurrentMinute(minute);
    mTimePicker.setOnTimeChangedListener(this);
    onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(),
            mTimePicker.getCurrentMinute());
}
 
Example 10
Source File: TimePickerPreference.java    From tickmate with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected View onCreateDialogView() {
    picker = new TimePicker(getContext());

    // Set the picker to the system default 24 hour format setting
    picker.setIs24HourView(new DateFormat().is24HourFormat(this.getContext()));
    return picker;
}
 
Example 11
Source File: TimePreference.java    From android with MIT License 5 votes vote down vote up
@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);
    mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
    mTimePicker.setIs24HourView(mIs24HourView);
    mTimePicker.setCurrentHour(mHour);
    mTimePicker.setCurrentMinute(mMinute);
}
 
Example 12
Source File: TimePickerDialogFragment.java    From android-styled-dialogs with Apache License 2.0 5 votes vote down vote up
@Override
protected BaseDialogFragment.Builder build(BaseDialogFragment.Builder builder) {
    builder = super.build(builder);
    mTimePicker = (TimePicker) builder.getLayoutInflater().inflate(R.layout.sdl_timepicker, null);
    mTimePicker.setIs24HourView(getArguments().getBoolean(ARG_24H));
    builder.setView(mTimePicker);

    TimeZone zone = TimeZone.getTimeZone(getArguments().getString(ARG_ZONE));
    mCalendar = Calendar.getInstance(zone);
    mCalendar.setTimeInMillis(getArguments().getLong(ARG_DATE, System.currentTimeMillis()));

    mTimePicker.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY));
    mTimePicker.setCurrentMinute(mCalendar.get(Calendar.MINUTE));
    return builder;
}
 
Example 13
Source File: DateFilterActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void prepareDialog(Dialog dialog, Calendar c) {
	DatePicker dp = dialog.findViewById(R.id.date);
	dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), null);
	TimePicker tp = dialog.findViewById(R.id.time);
       tp.setIs24HourView(is24HourFormat(this));
       tp.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
	tp.setCurrentMinute(c.get(Calendar.MINUTE));
}
 
Example 14
Source File: TimePreference.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected View onCreateDialogView() {
    picker = new TimePicker(getContext());
    picker.setIs24HourView(true);

    return (picker);
}
 
Example 15
Source File: TimePreference.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected View onCreateDialogView() {
	picker = new TimePicker(getContext());
	picker.setIs24HourView(android.text.format.DateFormat.is24HourFormat(getContext()));
	return picker;
}
 
Example 16
Source File: TimePreference.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected View onCreateDialogView() {
    picker = new TimePicker(getContext());
    picker.setIs24HourView(android.text.format.DateFormat.is24HourFormat(getContext()));
    return picker;
}
 
Example 17
Source File: TimePickerDialog.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void initWidget(View view) {
    this.container = view.findViewById(R.id.dialog_time_picker_container);

    Button done = view.findViewById(R.id.dialog_time_picker_done);
    done.setOnClickListener(v -> {
        String hourText;
        String minuteText;

        if (hour < 10) {
            hourText = "0" + hour;
        } else {
            hourText = Integer.toString(hour);
        }

        if (minute < 10) {
            minuteText = "0" + minute;
        } else {
            minuteText = Integer.toString(minute);
        }

        if (startTime) {
            ThemeManager.getInstance(getActivity())
                    .setNightStartTime(getActivity(), hourText + ":" + minuteText);
        } else {
            ThemeManager.getInstance(getActivity())
                    .setNightEndTime(getActivity(), hourText + ":" + minuteText);
        }

        if (listener != null) {
            listener.timeChanged();
        }

        dismiss();
    });

    Button cancel = view.findViewById(R.id.dialog_time_picker_cancel);
    cancel.setOnClickListener(v -> dismiss());

    TimePicker timePicker = view.findViewById(R.id.dialog_time_picker_time_picker);
    timePicker.setIs24HourView(true);
    timePicker.setOnTimeChangedListener((view1, hourOfDay, minute) -> {
        this.hour = hourOfDay;
        this.minute = minute;
    });
}
 
Example 18
Source File: TimePreference.java    From Birdays with Apache License 2.0 4 votes vote down vote up
@Override
protected View onCreateDialogView() {
    picker = new TimePicker(getContext());
    picker.setIs24HourView(DateFormat.is24HourFormat(getContext()));
    return (picker);
}
 
Example 19
Source File: TimeFragment.java    From SlideDateTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * Create and return the user interface view for this fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    int theme = getArguments().getInt("theme");
    int initialHour = getArguments().getInt("hour");
    int initialMinute = getArguments().getInt("minute");
    boolean isClientSpecified24HourTime = getArguments().getBoolean("isClientSpecified24HourTime");
    boolean is24HourTime = getArguments().getBoolean("is24HourTime");

    // Unless we inflate using a cloned inflater with a Holo theme,
    // on Lollipop devices the TimePicker will be the new-style
    // radial TimePicker, which is not what we want. So we will
    // clone the inflater that we're given but with our specified
    // theme, then inflate the layout with this new inflater.

    Context contextThemeWrapper = new ContextThemeWrapper(
            getActivity(),
            theme == SlideDateTimePicker.HOLO_DARK ?
                     android.R.style.Theme_Holo :
                     android.R.style.Theme_Holo_Light);

    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

    View v = localInflater.inflate(R.layout.fragment_time, container, false);

    mTimePicker = (TimePicker) v.findViewById(R.id.timePicker);
    // block keyboard popping up on touch
    mTimePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
    mTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute)
        {
            mCallback.onTimeChanged(hourOfDay, minute);
        }
    });

    // If the client specifies a 24-hour time format, set it on
    // the TimePicker.
    if (isClientSpecified24HourTime)
    {
        mTimePicker.setIs24HourView(is24HourTime);
    }
    else
    {
        // If the client does not specify a 24-hour time format, use the
        // device default.
        mTimePicker.setIs24HourView(DateFormat.is24HourFormat(
            getTargetFragment().getActivity()));
    }

    mTimePicker.setCurrentHour(initialHour);
    mTimePicker.setCurrentMinute(initialMinute);

    // Fix for the bug where a TimePicker's onTimeChanged() is not called when
    // the user toggles the AM/PM button. Only applies to 4.0.0 and 4.0.3.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
        Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
    {
        fixTimePickerBug18982();
    }

    return v;
}
 
Example 20
Source File: DateViewItem.java    From LibreTasks with Apache License 2.0 3 votes vote down vote up
/**
 * Class Constructor.
 * 
 * @param id
 *          the id used to uniquely identify this object.
 * @param dataTypeDbID
 *          the database id for {@link OmniArea}
 * @param activity
 *          the activity where this view item is to be built on
 */
public DateViewItem(int id, long dataTypeDbID, Activity activity) {
  super(id, dataTypeDbID);

  timePicker = new TimePicker(activity);
  timePicker.setId(id);
  timePicker.setIs24HourView(false);
}