Android TimePicker - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TimePicker class.

This code example shows how to use the following methods:setCurrentHour, setCurrentMinute, setIs24HourView, setOnTimeChangedListener
     * @see android.preference.DialogPreference#onCreateDialogView() 
     */ 
    @Override 
    protected View onCreateDialogView() {
 
        TimePicker tp = new TimePicker(getContext());
        tp.setIs24HourView(DateFormat.is24HourFormat(getContext()));
        tp.setOnTimeChangedListener(this);
        originalHour = getHour();
        originalMinute = getMinute();
        if (originalHour >= 0 && originalMinute >= 0) {
            tp.setCurrentHour(originalHour);
            tp.setCurrentMinute(originalMinute);
        } 
 
        return tp;
    } 
 
    /** 
     * @see 
9
CodeRank
This code example shows how to use the following methods:setCurrentHour, setCurrentMinute
			activityUtils.getCurrentActivity(false).runOnUiThread(new Runnable()
			{ 
				public void run() 
				{ 
					try{ 
						timePicker.setCurrentHour(hour);
						timePicker.setCurrentMinute(minute);
					}catch (Exception ignored){}
				} 
			}); 
		} 
	} 
	 
 
	/** 
	 * Sets the progress of a given {@link ProgressBar}. Examples are SeekBar and RatingBar. 
	 * @param progressBar the {@code ProgressBar} 
	 * @param progress the progress that the {@code ProgressBar} should be set to 
	 */ 
 
7
CodeRank
This code example shows how to use the following methods:getCurrentHour, getCurrentMinute, setCurrentHour, setCurrentMinute
    @Override 
    public void onDateChanged(DatePicker view, int year,
            int month, int day) {
        // Signal a time change so the max/min checks can be applied. 
        if (mTimePicker != null) {
            onTimeChanged(mTimePicker, mTimePicker.getCurrentHour(),
                    mTimePicker.getCurrentMinute());
        } 
    } 
 
    @Override 
    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
        Time time = new Time();
        time.set(0, mTimePicker.getCurrentMinute(),
                mTimePicker.getCurrentHour(), mDatePicker.getDayOfMonth(),
                mDatePicker.getMonth(), mDatePicker.getYear());
 
        if (time.toMillis(true) < mMinTimeMillis) {
            time.set(mMinTimeMillis);
        } else if (time.toMillis(true) > mMaxTimeMillis) {

7
CodeRank
This code example shows how to use the following methods:getCurrentHour, getCurrentMinute
 
        mCheckIsEndTime.setChecked(mKind == mPrefs.getCountDownTarget());
    } 
 
    public void onClickOk(View v) {
        int hour = mTimePicker.getCurrentHour();
        int min = mTimePicker.getCurrentMinute();
 
        mPrefs.setBellTime(mKind, hour * 3600 + min * 60);
        if (mCheckIsEndTime.isChecked()) {
            mPrefs.setCountDownTarget(mKind);
        } 
        finish();
    } 
 
    public void onClickCancel(View v) {
        finish();
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setCurrentHour, setCurrentMinute, setOnTimeChangedListener
     */ 
    @Override 
    protected View onCreateDialogView()
    { 
 
        TimePicker tp = new TimePicker(getContext());
        tp.setOnTimeChangedListener(this);
 
        int h = getHour();
        int m = getMinute();
        if (h >= 0 && m >= 0)
        { 
            tp.setCurrentHour(h);
            tp.setCurrentMinute(m);
        } 
 
        return tp;
    } 
 
    /* 
6
CodeRank
This code example shows how to use the following methods:getCurrentHour, getCurrentMinute
    } 
 
    private void tryNotifyDateTimeSet() { 
        if (mCallBack != null) {
            mDatePicker.clearFocus();
            mCallBack.onDateTimeSet(mDatePicker, mTimePicker, mDatePicker.getYear(),
                    mDatePicker.getMonth(), mDatePicker.getDayOfMonth(),
                    mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute());
        } 
    } 
 
    @Override 
    protected void onStop() { 
        if (Build.VERSION.SDK_INT >= 16) {
            tryNotifyDateTimeSet(); 
        } 
        super.onStop(); 
    } 
 
    @Override 
7
CodeRank
This code example shows how to use the following methods:clearFocus, getCurrentHour, getCurrentMinute
			this.setButton(DialogInterface.BUTTON_POSITIVE, getContext().getText(android.R.string.ok), new DialogInterface.OnClickListener()
			{ 
				@Override 
				public void onClick(DialogInterface dialog, int which)
				{ 
					picker.clearFocus(); // focus must be cleared so the value change listener is called
					callback.onTimeSet(picker, picker.getCurrentHour(), picker.getCurrentMinute());
				} 
			}); 
		} 
		catch(Exception e)
		{ 
			// reflection probably failed 
		} 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:setCurrentHour, setCurrentMinute, setIs24HourView, setOnTimeChangedListener
     * @see android.preference.DialogPreference#onCreateDialogView() 
     */ 
    @Override 
    protected View onCreateDialogView() {
 
        TimePicker tp = new TimePicker(getContext());
        tp.setIs24HourView(DateFormat.is24HourFormat(getContext()));
        tp.setOnTimeChangedListener(this);
        originalHour = getHour();
        originalMinute = getMinute();
        if (originalHour >= 0 && originalMinute >= 0) {
            tp.setCurrentHour(originalHour);
            tp.setCurrentMinute(originalMinute);
        } 
 
        return tp;
    } 
 
    /** 
     * @see 
7
CodeRank
This code example shows how to use the following methods:setEnabled
		initialization(); 
	} 
	 
	private void setFieldsEnabled(boolean v) {
		_datePicker.setEnabled(v);
		_timePicker.setEnabled(v);
		_okButton.setEnabled(v);
		_cancelButton.setEnabled(v);
	} 
	 
	private void sendResult(String callback, Calendar result, byte[] opaque) {
		this.setFieldsEnabled(false);
		long res = result == null ? 0 : result.getTimeInMillis()/((long)1000);
		Logger.D(TAG, "Return result: " + res);
		DateTimePicker.callback(callback, res, opaque, result == null);
		finish(); 
	} 
	 
	@Override 
	public void onConfigurationChanged(Configuration newConfig) {
6
CodeRank
This code example shows how to use the following methods:setCurrentHour, setCurrentMinute, setIs24HourView, setOnTimeChangedListener
		setSummary(_time);
	} 
 
	@Override 
	protected View onCreateDialogView() {
		tp = new TimePicker(getContext());
		tp.setIs24HourView(true);
 
		tp.setCurrentHour(time.getHours());
		tp.setCurrentMinute(time.getMinutes());
 
		tp.setOnTimeChangedListener(this);
 
		return tp;
	} 
 
	@Override 
	public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
		// TODO Auto-generated method stub 
		// Date date = new Date(0, 0, 0, view.getCurrentHour(), 
6
CodeRank

Related Android TimePicker Questions & Answers:

Other Android TimePicker Examples

14:	    }
15:	
16:	    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
17:	        // Do something with the time chosen by the user
18:	    }

Read More

See Code Examples for Android TimePicker Methods: