android.text.format.DateFormat#is24HourFormat ( )源码实例Demo

下面列出了android.text.format.DateFormat#is24HourFormat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: callmeter   文件: AddLogActivity.java
@Override
public void onClick(final View v) {
    switch (v.getId()) {
        case R.id.date:
            DatePickerDialog dpd = new DatePickerDialog(this, this, cal.get(Calendar.YEAR),
                    cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
            dpd.show();
            break;
        case R.id.time:
            TimePickerDialog dtp = new TimePickerDialog(this, this,
                    cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
                    DateFormat.is24HourFormat(this));
            dtp.show();
            break;
        default:
            break;
    }
}
 
源代码2 项目: QuickLyric   文件: SettingsFragment.java
@Override
public void onTimeSet(RadialPickerLayout radialPickerLayout, int h, int min) {
    if (nightTimeStart[0] >= 25) {
        nightTimeStart = new int[]{h, min};
        boolean twentyFourHourStyle = DateFormat.is24HourFormat(getActivity());
        TimePickerDialog tpd = TimePickerDialog
                .newInstance(this, 6, 0, twentyFourHourStyle);
        tpd.setOnCancelListener(this);
        tpd.setTitle(getActivity().getString(R.string.nighttime_end_dialog_title));
        tpd.show(getFragmentManager(), NIGHT_END_TIME_DIALOG_TAG);
    } else {
        SharedPreferences current = getActivity().getSharedPreferences("night_time", Context.MODE_PRIVATE);
        current.edit().putInt("startHour", nightTimeStart[0])
                .putInt("startMinute", nightTimeStart[1])
                .putInt("endHour", h)
                .putInt("endMinute", min)
                .apply();

        nightTimeStart[0] = 42;
    }
}
 
源代码3 项目: MaterialScrollBar   文件: DateAndTimeIndicator.java
@Override
protected int getIndicatorWidth() {
    int width = 62;
    if(includeYear) {
        if(includeDay) {
            width += 14;
        }
        width += 56;
    }
    if(includeMonth) {
        width += 43;
    }
    if(includeDay) {
        width += 28;
    }
    if(includeTime) {
        if(DateFormat.is24HourFormat(context)) {
            width += 70;
        } else {
            width += 115;
        }
    }
    return width;
}
 
源代码4 项目: openScale   文件: TimePreferenceDialog.java
@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);

    timePicker = view.findViewById(R.id.timePicker);
    calendar = Calendar.getInstance();

    Long timeInMillis = null;
    DialogPreference preference = getPreference();

    if (preference instanceof TimePreference) {
        TimePreference timePreference = (TimePreference) preference;
        timeInMillis = timePreference.getTimeInMillis();
    }

    if (timeInMillis != null) {
        calendar.setTimeInMillis(timeInMillis);
        boolean is24hour = DateFormat.is24HourFormat(getContext());

        timePicker.setIs24HourView(is24hour);
        timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
        timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
    }
}
 
源代码5 项目: GLEXP-Team-onebillion   文件: OBSetupMenu.java
void showPickTimeDialog (final TimePickerDialog.OnTimeSetListener listener)
{
    final DatePickerDialog.OnDateSetListener dateListener = (DatePickerDialog.OnDateSetListener) listener;
    final Calendar calendar = Calendar.getInstance();
    TimePickerDialog d = new TimePickerDialog(MainActivity.mainActivity, listener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), DateFormat.is24HourFormat(MainActivity.mainActivity));
    //
    d.setCancelable(false);
    d.setCanceledOnTouchOutside(false);
    //
    d.setButton(DatePickerDialog.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick (DialogInterface dialog, int which)
        {
            if (screenType == ScreenType.SET_DATE_SCREEN)
            {
                showPickDateDialog(dateListener, null);
            }
            else
            {
                MainActivity.log("OBSetupMenu:showPickTimeDialog:cancelled!");
            }
        }
    });
    //
    LinearLayout linearLayout = new LinearLayout(MainActivity.mainActivity.getApplicationContext());
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setCustomTitle(linearLayout);
    //
    d.show();
}
 
源代码6 项目: xDrip-Experimental   文件: EditAlertActivity.java
static public String timeFormatString(Context context, int hour, int minute) {
    SimpleDateFormat timeFormat24 = new SimpleDateFormat("HH:mm");
    String selected = hour+":" + ((minute<10)?"0":"") + minute;
    if (!DateFormat.is24HourFormat(context)) {
        try {
            Date date = timeFormat24.parse(selected);
            SimpleDateFormat timeFormat12 = new SimpleDateFormat("hh:mm aa");
            return timeFormat12.format(date);
        } catch (final ParseException e) {
            e.printStackTrace();
        }
    }
    return selected;
}
 
源代码7 项目: MiBandDecompiled   文件: AlarmActivity.java
protected void onResume()
{
    super.onResume();
    checkOnceAlarmIfExpired();
    new DateFormat();
    q = DateFormat.is24HourFormat(this);
    if (i != null)
    {
        i.notifyDataSetChanged();
    }
    UmengAnalytics.startPage("PageAlarm");
    UmengAnalytics.startSession(this);
}
 
源代码8 项目: NightWatch   文件: EditAlertActivity.java
public String timeFormatString(int Hour, int Minute) {
    SimpleDateFormat timeFormat24 = new SimpleDateFormat("HH:mm");
    String selected = Hour+":"+Minute;
    if (!DateFormat.is24HourFormat(mContext)) {
        try {
            Date date = timeFormat24.parse(selected);
            SimpleDateFormat timeFormat12 = new SimpleDateFormat("hh:mm aa");
            return timeFormat12.format(date);
        } catch (final ParseException e) {
            e.printStackTrace();
        }
    }
    return selected;
}
 
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
 
源代码10 项目: recurrence   文件: DateAndTimeUtil.java
public static String toStringReadableTime(Calendar calendar, Context context) {
    if (DateFormat.is24HourFormat(context)) {
        return READABLE_TIME_24_FORMAT.format(calendar.getTime());
    } else {
        return READABLE_TIME_FORMAT.format(calendar.getTime());
    }
}
 
源代码11 项目: ReminderDatePicker   文件: TimeSpinner.java
private boolean is24HourFormat(java.text.DateFormat timeFormat) {
    String pattern;
    try {
        pattern = ((SimpleDateFormat) timeFormat).toLocalizedPattern();
    } catch (ClassCastException e) {
        // we cannot get the pattern, use the default setting for out context:
        return DateFormat.is24HourFormat(getContext());
    }
    // if pattern does not contain the 12 hour formats, we return true (regardless of any 'a' (am/pm) modifier)
    return !(pattern.contains("h") || pattern.contains("K"));
}
 
源代码12 项目: android   文件: PrayerListView.java
public PrayerListView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(context).inflate(R.layout.view_default_prayer, this, true);
    ButterKnife.bind(this);

    mDateFormat = DateFormat.is24HourFormat(context) ? FORMAT_24 : FORMAT_12;
}
 
private void initialize(Context context, MapboxNavigation mapboxNavigation) {
  this.mapboxNavigation = mapboxNavigation;
  etaFormat = context.getString(R.string.eta_format);
  initializeDistanceFormatter(context, mapboxNavigation);
  notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  isTwentyFourHourFormat = DateFormat.is24HourFormat(context);
  createNotificationChannel(context);
  buildNotification(context);
  registerReceiver(context);
}
 
源代码14 项目: TabletClock   文件: TimeViewUpdater.java
public boolean retrive24Format() { // return true if changed
	boolean old = is24hours;
	is24hours = DateFormat.is24HourFormat(mTimeView.getContext());
	return old != is24hours;
}
 
@Before
public void setup() {
    mLocaleModel = new LocaleModel(mActivityTestRule.getActivity());
    mInitiallyIn24HourMode = DateFormat.is24HourFormat(mActivityTestRule.getActivity());
}
 
源代码16 项目: android   文件: DashClockService.java
private String getFormattedDate(Date date) {
    String f = DateFormat.is24HourFormat(this) ? FORMAT_24 : FORMAT_12;
    return DateFormat.format(f, date).toString();
}
 
源代码17 项目: react-native-datetime-picker   文件: TimePicker.java
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new RCTTimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
 
源代码18 项目: GeometricWeather   文件: TimeManager.java
public static boolean is12Hour(Context context) {
    return !DateFormat.is24HourFormat(context);
}
 
源代码19 项目: QuickLyric   文件: SettingsFragment.java
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
    switch (pref.getKey()) {
        case "pref_theme":
            findPreference("pref_theme").setSummary(themes[Integer.valueOf((String) newValue)]);
            break;
        case "pref_notifications":
            if (newValue.equals("0")) {
                ((NotificationManager) getActivity()
                        .getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll();
            } else
                broadcast();
            break;
        case "pref_night_mode":
            if ((Boolean) newValue) {
                boolean twentyFourHourStyle = DateFormat.is24HourFormat(getActivity());
                TimePickerDialog tpd = TimePickerDialog
                        .newInstance(this, 21, 0, twentyFourHourStyle);
                tpd.setOnCancelListener(this);
                tpd.setTitle(getActivity().getString(R.string.nighttime_start_dialog_title));
                tpd.show(getFragmentManager(), NIGHT_START_TIME_DIALOG_TAG);
            } else {
                this.onCancel(null);
            }
            break;
        case "pref_overlay":
            findPreference("pref_overlay_behavior").setEnabled((Boolean) newValue);
            findPreference("pref_notifications").setEnabled(!((Boolean) newValue));
            findPreference("pref_notifications").setSummary((Boolean) newValue ?
                    R.string.pref_notification_sum_disabled : R.string.pref_notifications_sum);
            if ((Boolean) newValue) {
                PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean(pref.getKey(), (Boolean) newValue).apply();
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(getActivity())) {
                    broadcast();
                } else {
                    final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getActivity().getPackageName()));
                    getActivity().startActivity(intent);
                }
                PermissionsChecker.displayMIUIPopupPermission(getActivity());
            } else {
                LyricsOverlayService.removeCustomFloatingView(getActivity());
            }
            break;
        case "pref_overlay_behavior":
            LyricsOverlayService.removeCustomFloatingView(getActivity());
            break;
    }
    return true;
}
 
源代码20 项目: android_9.0.0_r45   文件: TextClock.java
/**
 * Indicates whether the system is currently using the 24-hour mode.
 *
 * When the system is in 24-hour mode, this view will use the pattern
 * returned by {@link #getFormat24Hour()}. In 12-hour mode, the pattern
 * returned by {@link #getFormat12Hour()} is used instead.
 *
 * If either one of the formats is null, the other format is used. If
 * both formats are null, the default formats for the current locale are used.
 *
 * @return true if time should be displayed in 24-hour format, false if it
 *         should be displayed in 12-hour format.
 *
 * @see #setFormat12Hour(CharSequence)
 * @see #getFormat12Hour()
 * @see #setFormat24Hour(CharSequence)
 * @see #getFormat24Hour()
 */
public boolean is24HourModeEnabled() {
    if (mShowCurrentUserTime) {
        return DateFormat.is24HourFormat(getContext(), ActivityManager.getCurrentUser());
    } else {
        return DateFormat.is24HourFormat(getContext());
    }
}