Example usage for android.text.format DateFormat is24HourFormat

List of usage examples for android.text.format DateFormat is24HourFormat

Introduction

In this page you can find the example usage for android.text.format DateFormat is24HourFormat.

Prototype

public static boolean is24HourFormat(Context context) 

Source Link

Document

Returns true if times should be formatted as 24 hour times, false if times should be formatted as 12 hour (AM/PM) times.

Usage

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

/**
 * Autodetect is done by default if nothing is specified
 *//*from ww  w.j ava  2  s .  c o  m*/
@Deprecated
public RadialTimePickerDialogFragment setAutodetectDateFormat(Context context) {
    mIs24HourMode = DateFormat.is24HourFormat(context);
    return this;
}

From source file:com.mattfred.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_HOUR_OF_DAY)
            && savedInstanceState.containsKey(KEY_MINUTE)
            && savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW)) {
        mInitialHourOfDay = savedInstanceState.getInt(KEY_HOUR_OF_DAY);
        mInitialMinute = savedInstanceState.getInt(KEY_MINUTE);
        mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
        mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
        mStyleResId = savedInstanceState.getInt(KEY_STYLE);
    } else {/*from w  ww  .  ja v a  2  s .c  o  m*/
        if (mIs24HourMode == null) {
            mIs24HourMode = DateFormat.is24HourFormat(getContext());
        }
    }
}

From source file:org.isoron.uhabits.activities.habits.edit.BaseDialog.java

private void showTimePicker(int defaultHour, int defaultMin) {
    boolean is24HourMode = DateFormat.is24HourFormat(getContext());
    TimePickerDialog timePicker = TimePickerDialog.newInstance(new OnTimeSetListener(), defaultHour, defaultMin,
            is24HourMode);/* w  w  w.  j  a  v  a 2s.com*/
    timePicker.show(getFragmentManager(), "timePicker");
}

From source file:com.finchuk.clock2.alarms.ui.BaseAlarmViewHolder.java

private void bindTime(Alarm alarm) {
    String time = DateFormat.getTimeFormat(getContext()).format(new Date(alarm.ringsAt()));
    if (DateFormat.is24HourFormat(getContext())) {
        mTime.setText(time);/* w w w. j  a  v  a 2 s  .  c o  m*/
    } else {
        TimeTextUtils.setText(time, mTime);
    }

    // Use a mock TextView to get our colors, because its ColorStateList is never
    // mutated for the lifetime of this ViewHolder (even when reused).
    // This solution is robust against dark/light theme changes, whereas using
    // color resources is not.
    TextView colorsSource = (TextView) itemView.findViewById(R.id.colors_source);
    ColorStateList colors = colorsSource.getTextColors();
    int def = colors.getDefaultColor();
    // Too light
    //        int disabled = colors.getColorForState(new int[] {-android.R.attr.state_enabled}, def);
    // Material guidelines say text hints and disabled text should have the same color.
    int disabled = colorsSource.getCurrentHintTextColor();
    // However, digging around in the system's textColorHint for 21+ says its 50% black for our
    // light theme. I'd like to follow what the guidelines says, but I want code that is robust
    // against theme changes. Alternatively, override the attribute values to what you want
    // in both your dark and light themes...
    //        int disabled = ContextCompat.getColor(getContext(), R.color.text_color_disabled_light);
    // We only have two states, so we don't care about losing the other state colors.
    mTime.setTextColor(alarm.isEnabled() ? def : disabled);
}

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_HOUR_OF_DAY)
            && savedInstanceState.containsKey(KEY_MINUTE)
            && savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW)) {
        mInitialHourOfDay = savedInstanceState.getInt(KEY_HOUR_OF_DAY);
        mInitialMinute = savedInstanceState.getInt(KEY_MINUTE);
        mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
        mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
        mStyleResId = savedInstanceState.getInt(KEY_STYLE);
        if (savedInstanceState.containsKey(KEY_FUTURE_MINUTES_LIMIT)) {
            mFutureMinutesLimit = savedInstanceState.getInt(KEY_FUTURE_MINUTES_LIMIT);
        }/*from   w w w .  j a  v  a 2 s  .c  o m*/
        if (savedInstanceState.containsKey(KEY_PAST_MINUTES_LIMIT)) {
            mPastMinutesLimit = savedInstanceState.getInt(KEY_PAST_MINUTES_LIMIT);
        }
        if (savedInstanceState.containsKey(KEY_CURRENT_DATE)) {
            mValidateDateTime = (Calendar) savedInstanceState.getSerializable(KEY_CURRENT_DATE);
        }
        if (savedInstanceState.containsKey(KEY_PICKER_DATE)) {
            mPickerDate = (Calendar) savedInstanceState.getSerializable(KEY_PICKER_DATE);
        }
    } else {
        if (mIs24HourMode == null) {
            mIs24HourMode = DateFormat.is24HourFormat(getContext());
        }
    }
}

From source file:com.gumgoose.app.quakebuddy.QuakeAdapter.java

/**
 * Helper method for getting the earthquake time
 *
 * @param time is the earthquake time as unix
 * @return     the earthquake time as a String
 *//* w w  w .  j  a  v  a 2  s.c  o  m*/
private String getStandardTime(long time) {
    if (DateFormat.is24HourFormat(getContext())) {
        // System is using the 24-hour time format
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        // Detect the system time zone
        sdf.setTimeZone(TimeZone.getDefault());
        // Return the local time in 24-hour format
        return sdf.format(time);
    } else {
        // System is using the 12-hour time format
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
        // Detect the system time zone
        sdf.setTimeZone(TimeZone.getDefault());
        // Return the local time in 12-hour format
        return sdf.format(time);
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.no1f1.No1F1Support.java

/**
 * Set display settings (time format and measurement system)
 *
 * @param transaction/*from  w  w  w.  java2s  .  c  om*/
 * @return
 */
private No1F1Support setDisplaySettings(TransactionBuilder transaction) {
    byte[] displayBytes = new byte[] { No1F1Constants.CMD_DISPLAY_SETTINGS, 0x00, // 1 - display distance in kilometers, 2 - in miles
            0x00 // 1 - display 24-hour clock, 2 - for 12-hour with AM/PM
    };
    String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM,
            getContext().getString(R.string.p_unit_metric));
    if (units.equals(getContext().getString(R.string.p_unit_metric))) {
        displayBytes[1] = 1;
    } else {
        displayBytes[1] = 2;
    }
    if (DateFormat.is24HourFormat(getContext())) {
        displayBytes[2] = 1;
    } else {
        displayBytes[2] = 2;
    }
    transaction.write(ctrlCharacteristic, displayBytes);
    return this;
}

From source file:de.spiritcroc.ownlog.ui.fragment.LogItemEditFragment.java

@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
    mTime.set(year, month, dayOfMonth);//from  w  w  w. j ava  2s .c  o  m

    new TimePickerDialog(getActivity(), this, mTime.get(Calendar.HOUR_OF_DAY), mTime.get(Calendar.MINUTE),
            DateFormat.is24HourFormat(getActivity())).show();
    updateTitle();
}

From source file:com.timekeeping.app.activities.MainActivity.java

/**
 * Added a new entry of {@link com.timekeeping.data.Time} to database.
 *//*from w ww  .  j  a  va  2s . c om*/
private void addNewTime() {
    mAddNewV.setVisibility(View.INVISIBLE);
    RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog.newInstance(this, 0, 0,
            DateFormat.is24HourFormat(this));
    timePickerDialog.setOnDismissListener(this);
    timePickerDialog.show(getSupportFragmentManager(), null);
}

From source file:com.timekeeping.app.activities.MainActivity.java

/**
 * Edit a entry of {@link com.timekeeping.data.Time} to database.
 *///from  w w w  .  j  a  v a 2 s . c o m
private void editTime() {
    mAddNewV.setVisibility(View.INVISIBLE);
    RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog.newInstance(this, mEditedTime.getHour(),
            mEditedTime.getMinute(), DateFormat.is24HourFormat(this));
    timePickerDialog.setOnDismissListener(this);
    timePickerDialog.show(getSupportFragmentManager(), null);
}