当前位置: 首页>>代码示例>>Java>>正文


Java TimePicker类代码示例

本文整理汇总了Java中android.widget.TimePicker的典型用法代码示例。如果您正苦于以下问题:Java TimePicker类的具体用法?Java TimePicker怎么用?Java TimePicker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TimePicker类属于android.widget包,在下文中一共展示了TimePicker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onBtnChooseTimeDialogClicked

import android.widget.TimePicker; //导入依赖的package包/类
@OnClick(R.id.btn_choose_time_dialog)
public void onBtnChooseTimeDialogClicked() {
    final Calendar calendar = Calendar.getInstance();
    TimePickerDialog dialog = new TimePickerDialog(
            this,
            new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    calendar.set(Calendar.MINUTE, minute);
                    String time = DateFormat.getTimeInstance(DateFormat.SHORT).format(calendar.getTime());
                    ToastUtils.showShortToast(time);
                }
            },
            calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE),
            false
    );
    dialog.show();
}
 
开发者ID:jiangkang,项目名称:KTools,代码行数:21,代码来源:KDialogActivity.java

示例2: showTime

import android.widget.TimePicker; //导入依赖的package包/类
private void showTime() {

    Calendar c = Calendar.getInstance();
    int mYear = c.get(Calendar.YEAR);
    int mMonth = c.get(Calendar.MONTH);
    int mDay = c.get(Calendar.DAY_OF_MONTH);
    int mHour = c.get(Calendar.HOUR_OF_DAY);
    int mMinute = c.get(Calendar.MINUTE);
    TimePickerDialog dialog =
        new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
          @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

          }
        }, mHour, mMinute, true);
    dialog.show();
  }
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:17,代码来源:DateUI.java

示例3: show

import android.widget.TimePicker; //导入依赖的package包/类
public AlertDialog show(Context context) {
    dialog = new AlertDialog.Builder(context).create();
    dialog.show();
    Window window = dialog.getWindow();
    window.setContentView(R.layout.dialog_date_time);
    window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
    //window.setWindowAnimations(R.style.in_left_out_right_style);
    window.setBackgroundDrawableResource(R.color.transparent);

    datePicker = (DatePicker) window
            .findViewById(R.id.date_time_datePicker1);
    datePicker.setCalendarViewShown(false);
    timePicker = (TimePicker) window.findViewById(R.id.date_time_timePicker);
    but_ok = (Button) window.findViewById(R.id.date_time_but_ok);
    but_ok.setOnClickListener(this);
    return dialog;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:18,代码来源:DialogDate.java

示例4: onTimeSet

import android.widget.TimePicker; //导入依赖的package包/类
@SuppressWarnings("WrongConstant")
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    int hour, min;
    Calendar datetime = Calendar.getInstance();
    String am_pm = "" ;
    datetime.set(Calendar.HOUR_OF_DAY, hourOfDay);
    datetime.set(Calendar.MINUTE, minute);

    if (datetime.get(Calendar.AM_PM) == Calendar.AM)
        am_pm = "AM";
    else if (datetime.get(Calendar.AM_PM) == Calendar.PM)
        am_pm = "PM";
    hourOfDay = hourOfDay > 12 ? hourOfDay - 12 : hourOfDay;
    hour = hourOfDay > 9 ? hourOfDay : hourOfDay;
    min = minute > 9 ? minute : minute;
    timeInterface.setTime(hour, min, am_pm);
}
 
开发者ID:pawanchauhan05,项目名称:AndroidUtility,代码行数:18,代码来源:AlertDialog.java

示例5: taskDueTimeOnClickBehavior

import android.widget.TimePicker; //导入依赖的package包/类
@OnClick(R.id.task_due_time_content)
void taskDueTimeOnClickBehavior() {
    TimePickerDialog.OnTimeSetListener time = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int hourOfDay, int minuteOfHour) {
            dueCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            dueCalendar.set(Calendar.MINUTE, minuteOfHour);
            DateFormat sdf = android.text.format.DateFormat.getTimeFormat(getBaseContext());
            dueTimeContent.setText(sdf.format(dueCalendar.getTime()));
            setTime = true;
        }
    };
    new TimePickerDialog(this, time,
            dueCalendar.get(Calendar.HOUR_OF_DAY),
            dueCalendar.get(Calendar.MINUTE), true).show();
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:17,代码来源:OperateTaskActivityBase.java

示例6: pickTime

import android.widget.TimePicker; //导入依赖的package包/类
/**
 * 弹出时间选择对话框
 * <p>
 * 参数:
 * title:标题
 * datetime 指定时间 yyyy-MM-dd HH:mm或者HH:mm
 * 返回:
 * time:格式:HH:mm
 */
public static void pickTime(IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
    String title = param.optString("title");
    String date = param.optString("datetime");
    final Calendar calendar = Calendar.getInstance();
    if (!TextUtils.isEmpty(date)) {
        if (date.contains(" ")) {
            calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
        } else {
            calendar.setTime(DateUtil.convertString2Date(date, "HH:mm"));
        }
    }
    DialogUtil.pickTime(webLoader.getPageControl().getActivity(), title, calendar, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);
            String chooseTime = DateUtil.convertDate(calendar.getTime(), "HH:mm");
            Map<String, Object> map = new HashMap<>();
            map.put("time", chooseTime);
            callback.applySuccess(map);
        }
    });
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:33,代码来源:UIApi.java

示例7: pickDateTime

import android.widget.TimePicker; //导入依赖的package包/类
/**
 * 弹出日期时间选择对话框
 * <p>
 * 参数:
 * title:标题
 * datetime 指定时间 yyyy-MM-dd HH:mm
 * 返回:
 * datetime:格式:yyyy-MM-dd HH:mm
 */
public static void pickDateTime(final IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
    String title1 = param.optString("title1");
    String title2 = param.optString("title2");
    String date = param.optString("datetime");
    final Calendar calendar = Calendar.getInstance();
    if (!TextUtils.isEmpty(date)) {
        calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
    }
    DialogUtil.pickDateTime(webLoader.getPageControl().getActivity(), title1, title2, calendar, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);
            String chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM-dd HH:mm");
            Map<String, Object> map = new HashMap<>();
            map.put("datetime", chooseDate);
            callback.applySuccess(map);
        }
    });
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:30,代码来源:UIApi.java

示例8: onCreate

import android.widget.TimePicker; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_event);
    mImageView = (ImageView) findViewById(R.id.imageView);
    mEventName  = (EditText) findViewById(R.id.enter_event_name);
    mEventDescription = (EditText) findViewById(R.id.enter_event_desc);
    mCreateEvent = (Button) findViewById(R.id.create_event);
    mdate = (DatePicker) findViewById(R.id.enter_event_date);
    mTime = (TimePicker) findViewById(R.id.enter_event_time);
    mCreateEvent.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            loading= ProgressDialog.show(CreateEventActivity.this,"Creating Event...","Please wait...",false,false);
            createEvent();
        }
    });

    if (isStoragePermissionGranted()){
        accessPic();
    }

}
 
开发者ID:rohansapre,项目名称:cleanhood,代码行数:24,代码来源:CreateEventActivity.java

示例9: onTimeSet

import android.widget.TimePicker; //导入依赖的package包/类
@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    editor.putLong("notificationPeriod", calendar.getTimeInMillis());
    editor.commit();

    Intent intent = new Intent(NotificationActivity.this, NotificationReceiver.class);
    intent.setAction(NotificationReceiver.ACTION_NOTIFICATION);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(NotificationActivity.this, 0, intent, 0);
    AlarmManager manager = (AlarmManager) NotificationActivity.this.getSystemService(Context.ALARM_SERVICE);
    manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 60000, pendingIntent);

    Toast.makeText(NotificationActivity.this, DateUtils.formatDateTime(NotificationActivity.this, calendar.getTimeInMillis(), DateUtils.FORMAT_SHOW_TIME), Toast.LENGTH_LONG).show();
}
 
开发者ID:kerick-jeff,项目名称:MyBP,代码行数:20,代码来源:NotificationActivity.java

示例10: onTimeSet

import android.widget.TimePicker; //导入依赖的package包/类
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    this.hour = hourOfDay;
    this.minute = minute;

    // Create calendar
    Calendar selectedCalendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
    selectedCalendar.set(Calendar.YEAR,year);
    selectedCalendar.set(Calendar.MONTH,month);
    selectedCalendar.set(Calendar.DAY_OF_MONTH,day);
    selectedCalendar.set(Calendar.HOUR_OF_DAY,hour);
    selectedCalendar.set(Calendar.MINUTE,0);
    selectedCalendar.set(Calendar.SECOND,0);
    selectedCalendar.set(Calendar.MILLISECOND,0);

    //
    Calendar now = Calendar.getInstance(TimeZone.getTimeZone("CET"));
    if (selectedCalendar.getTimeInMillis() > now.getTimeInMillis()){
        selectedCalendar.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY));
    }
    if (listener != null) {
        listener.onDateTimeSet(selectedCalendar);
    } else {
        Log.w("DatePickerFragment","There is no listener");
    }
}
 
开发者ID:medialab-prado,项目名称:puremadrid,代码行数:27,代码来源:DatePickerFragment.java

示例11: testSettingPmTimeDisplays24HourTime

import android.widget.TimePicker; //导入依赖的package包/类
@Test
public void testSettingPmTimeDisplays24HourTime() {
    onListItem(1).perform(click());

    onView(withId(R.id.fragment_note_deadline_button)).check(matches(allOf(withText(R.string.deadline_button_hint), isDisplayed())));
    onView(withId(R.id.fragment_note_deadline_button)).perform(click());

    /* Set date. */
    onView(withId(R.id.dialog_timestamp_date_picker)).perform(click());
    onView(withClassName(equalTo(DatePicker.class.getName()))).perform(setDate(2014, 4, 1));
    onView(withText(R.string.ok)).perform(click());

    /* Set time. */
    onView(withId(R.id.dialog_timestamp_time_picker)).perform(scrollTo(), click());
    onView(withClassName(equalTo(TimePicker.class.getName()))).perform(setTime(15, 15));
    onView(withText(R.string.ok)).perform(click());

    onView(withText(R.string.set)).perform(click());

    onView(withId(R.id.fragment_note_deadline_button)).check(matches(allOf(withText(userDateTime("<2014-04-01 Tue 15:15>")), isDisplayed())));
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:22,代码来源:NoteFragmentTest.java

示例12: testSchedulingNote

import android.widget.TimePicker; //导入依赖的package包/类
@Test
public void testSchedulingNote() {
    defaultSetUp();

    onView(withId(R.id.drawer_layout)).perform(open());
    onView(withText("Scheduled")).perform(click());
    onView(allOf(withId(android.R.id.list), isDisplayed())).check(matches(listViewItemCount(2)));

    onView(allOf(withText(endsWith("Note C.")), isDisplayed())).perform(longClick());
    onView(withId(R.id.query_cab_edit)).perform(click());
    onView(withText(R.string.schedule)).perform(click());

    onView(withId(R.id.dialog_timestamp_date_picker)).perform(click());
    onView(withClassName(equalTo(DatePicker.class.getName()))).perform(setDate(2014, 4, 1));
    onView(withText(R.string.ok)).perform(click());
    onView(withId(R.id.dialog_timestamp_time_picker)).perform(scrollTo(), click());
    onView(withClassName(equalTo(TimePicker.class.getName()))).perform(setTime(9, 15));
    onView(withText(R.string.ok)).perform(click());
    onView(withText(R.string.set)).perform(click());

    onView(allOf(withId(android.R.id.list), isDisplayed())).check(matches(listViewItemCount(2)));
    onView(withText(userDateTime("<2014-04-01 Tue 09:15>"))).check(matches(isDisplayed()));
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:24,代码来源:QueryFragmentTest.java

示例13: onTimeSet

import android.widget.TimePicker; //导入依赖的package包/类
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();

    calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
    calSet.set(Calendar.MINUTE, minute);
    calSet.set(Calendar.SECOND, 0);
    calSet.set(Calendar.MILLISECOND, 0);

    if (calSet.compareTo(calNow) <= 0) {
        // Today Set time passed, count to tomorrow
        calSet.add(Calendar.DATE, 1);
    }

    setAlarm(calSet);
}
 
开发者ID:bilal-rashid,项目名称:Lazy-Switches,代码行数:19,代码来源:BluetoothActivity.java

示例14: reminderTimePickerDialog

import android.widget.TimePicker; //导入依赖的package包/类
public void reminderTimePickerDialog() {
    final Calendar calendar = Calendar.getInstance();
    int mHour = calendar.get(Calendar.HOUR_OF_DAY);
    int mMinute = calendar.get(Calendar.MINUTE);

    final SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("hh:mm a", Locale.US);

    final ToodooTimePickerDialog timePickerDialog = new ToodooTimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int hour, int minute) {
            reminderCalendar.set(Calendar.HOUR_OF_DAY, hour);
            reminderCalendar.set(Calendar.MINUTE, minute);
            selectedReminderValue = reminderCalendar.getTime();
            reminderTimeValue = simpleTimeFormat.format(selectedReminderValue);

            selectedReminder = reminderDateValue + " @ " + reminderTimeValue;

            ToodooOptionsModel ToodooOptionsModel = toodooOptionsList.get(2);
            ToodooOptionsModel.setOptionValue(selectedReminder);
            mAdapter.notifyDataSetChanged();
        }
    }, mHour, mMinute, true);
    timePickerDialog.show();
}
 
开发者ID:OlayinkaPeter,项目名称:Toodoo,代码行数:25,代码来源:ToodooNote.java

示例15: showTimePickerDialog

import android.widget.TimePicker; //导入依赖的package包/类
/**
 * Shows time picker dialog and handles the time selected by user
 * @param viewWhoIsCallingIt View whose time time needs to be updated after user selects time
 * @param prefKey Preference for the key needed to be updated after user selects time
 */
private void showTimePickerDialog(final KeyValueView viewWhoIsCallingIt, final String prefKey) {
    int time[] = TimeUtils.getCurrentTimeAsHourAndMinutes();
    TimePickerDialog timePickerDialog = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker timePicker, int i, int i1) {
            String selectedHour = i < 10 ? "0" + i: "" + i;
            String selectedMinute = i1 < 10 ? "0" +i1: "" + i1;
            String timeString = selectedHour + ":" + selectedMinute;

            PreferenceHelper.putString(context, prefKey, timeString);
            // We also backup the time here
            // To get the prefKey for backup, its "last_" + prefKey
            PreferenceHelper.putString(context, "last_" + prefKey, timeString);

            viewWhoIsCallingIt.setValue(timeString);

            addNextDayIfNecessary();

            doCurrentAutoFunctions(true);
        }
    }, time[0], time[1], false);
    timePickerDialog.show();
}
 
开发者ID:corphish,项目名称:NightLight,代码行数:29,代码来源:AutoFragment.java


注:本文中的android.widget.TimePicker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。