Example usage for android.text.format DateUtils DAY_IN_MILLIS

List of usage examples for android.text.format DateUtils DAY_IN_MILLIS

Introduction

In this page you can find the example usage for android.text.format DateUtils DAY_IN_MILLIS.

Prototype

long DAY_IN_MILLIS

To view the source code for android.text.format DateUtils DAY_IN_MILLIS.

Click Source Link

Usage

From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java

@BindingAdapter("relativeDateTime")
public static void setRelativeDateTime(TextView textView, long datetime) {
    textView.setText(DateUtils.getRelativeDateTimeString(textView.getContext(), datetime,
            DateUtils.MINUTE_IN_MILLIS, DateUtils.DAY_IN_MILLIS, 0));
}

From source file:com.abourazanis.muzei.wallbase.WallhavenSettings.java

private void setupIntervalSpinner() {
    mIntervalList.clear();//from  ww  w.ja  v  a 2 s . c  om
    mIntervalList.add(new Interval(R.string.threeHours, 3 * DateUtils.HOUR_IN_MILLIS));
    mIntervalList.add(new Interval(R.string.sixHours, 6 * DateUtils.HOUR_IN_MILLIS));
    mIntervalList.add(new Interval(R.string.nineHours, 9 * DateUtils.HOUR_IN_MILLIS));
    mIntervalList.add(new Interval(R.string.twelveHours, 12 * DateUtils.HOUR_IN_MILLIS));
    mIntervalList.add(new Interval(R.string.day, DateUtils.DAY_IN_MILLIS));

    mUpdateIntervalSpinner
            .setAdapter(new ArrayAdapter<Interval>(this, android.R.layout.simple_list_item_1, mIntervalList));
    mUpdateIntervalSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            PreferenceHelper.setConfigFreq(view.getContext(),
                    (int) mIntervalList.get(position).getTimeMillis());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    int preference = PreferenceHelper.getConfigFreq(this);

    for (int i = 0; i < mIntervalList.size(); i++)
        if (preference == mIntervalList.get(i).getTimeMillis()) {
            mUpdateIntervalSpinner.setSelection(i, true);
        }
}

From source file:com.handlerexploit.news.MainActivity.java

public void clearFolder(final File directory, int numDays) {
    if (directory != null && directory.isDirectory()) {
        for (File child : directory.listFiles()) {
            try {
                if (child.isDirectory()) {
                    clearFolder(child, numDays);
                }/*ww w.  ja va2  s . c om*/

                if (child.lastModified() < new Date().getTime() - numDays * DateUtils.DAY_IN_MILLIS) {
                    child.delete();
                }
            } catch (Throwable ignored) {
            }
        }
    }
}

From source file:ca.mudar.snoozy.ui.widget.HistoryCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);

    /*/*from ww  w .ja  v  a2s.  c  om*/
     Get current cursor values
      */
    final boolean isPowerOn = (1 == cursor.getInt(HistoryQuery.IS_POWER_ON));
    final long timestamp = cursor.getLong(HistoryQuery.TIME_STAMP);
    final boolean isFirst = (1 == cursor.getInt(HistoryQuery.IS_FIRST));
    final boolean isLast = (1 == cursor.getInt(HistoryQuery.IS_LAST));
    final int batteryLevel = cursor.getInt(HistoryQuery.BATTERY_LEVEL);

    /*
     Prepare the data
      */
    final String sPowerStatus = mResources.getString(
            isPowerOn ? R.string.history_item_power_connected : R.string.history_item_power_disconnected);
    final String sBatteryLevel = String.format(mResources.getString(R.string.history_item_battery_level),
            batteryLevel);
    final int resPowerStatusColor = mResources
            .getColor(isPowerOn ? R.color.card_row_highlight_color : R.color.card_row_color);

    String sTimestamp;
    String sDay;

    if (DateUtils.isToday(timestamp)) {
        sDay = mResources.getString(R.string.history_item_day_today);
        sTimestamp = (String) DateUtils.formatSameDayTime(timestamp, mMillis, 0, DateFormat.SHORT);
        //            sTimestamp = (String) DateUtils.getRelativeTimeSpanString(timestamp,now, 0, 0);
    } else {
        sDay = (String) DateUtils.getRelativeTimeSpanString(timestamp, mMillis, DateUtils.DAY_IN_MILLIS,
                DateUtils.FORMAT_ABBREV_RELATIVE);
        //            sDay = sDay.substring(0,1).toUpperCase() + sDay.substring(1);
        sTimestamp = mTimeFormat.format(new Date(timestamp));
    }
    sDay = sDay.substring(0, 1).toUpperCase() + sDay.substring(1);

    /*
     Set UI values
     */
    ((TextView) view.findViewById(R.id.history_is_power_on)).setText(sPowerStatus);
    ((TextView) view.findViewById(R.id.history_is_power_on)).setTextColor(resPowerStatusColor);
    ((TextView) view.findViewById(R.id.history_timestamp)).setText(sTimestamp);
    ((TextView) view.findViewById(R.id.history_battery_level)).setText(sBatteryLevel);

    if (isFirst && isLast) {
        ((TextView) view.findViewById(R.id.history_day)).setText(sDay);

        view.findViewById(R.id.history_header).setVisibility(View.VISIBLE);

        view.setBackgroundResource(R.drawable.bg_cards_top_bottom);
    } else if (isLast) {
        ((TextView) view.findViewById(R.id.history_day)).setText(sDay);

        view.findViewById(R.id.history_header).setVisibility(View.VISIBLE);

        view.setBackgroundResource(R.drawable.bg_cards_top);
    } else if (isFirst) {
        view.findViewById(R.id.history_header).setVisibility(View.GONE);

        view.setBackgroundResource(R.drawable.bg_cards_bottom);
    } else {
        view.findViewById(R.id.history_header).setVisibility(View.GONE);

        view.setBackgroundResource(R.drawable.bg_cards_middle);
    }
}

From source file:com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment.java

/**
 * {@inheritDoc}//from  w  w  w. j a  va2s  . c  om
 *
 * @return A new dialog to let the user choose an expiration date that will be bound to a share link.
 */
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Chosen date received as an argument must be later than tomorrow ; default to tomorrow in other case
    final Calendar chosenDate = Calendar.getInstance();
    long tomorrowInMillis = chosenDate.getTimeInMillis() + DateUtils.DAY_IN_MILLIS;
    long chosenDateInMillis = getArguments().getLong(ARG_CHOSEN_DATE_IN_MILLIS);
    long maxDateInMillis = getArguments().getLong(ARG_MAX_DATE_IN_MILLIS);

    if (chosenDateInMillis < tomorrowInMillis) {
        chosenDateInMillis = tomorrowInMillis;
    }
    chosenDate.setTimeInMillis(chosenDateInMillis);

    // Create a new instance of DatePickerDialog
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, chosenDate.get(Calendar.YEAR),
            chosenDate.get(Calendar.MONTH), chosenDate.get(Calendar.DAY_OF_MONTH));

    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.share_cancel_public_link_button),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (which == DialogInterface.BUTTON_NEGATIVE) {
                        // Do Stuff
                        notifyDatePickerListener(null);
                    }
                }
            });

    // Prevent days in the past may be chosen
    DatePicker picker = dialog.getDatePicker();
    if (maxDateInMillis >= chosenDateInMillis) {
        // the extra second (+1000) is required to prevent a bug of DatePicker that shows
        // an extra header with the selected date if maxDateInMillis == chosenDateInMillis
        picker.setMaxDate(maxDateInMillis + 1000);
    }
    picker.setMinDate(tomorrowInMillis - 1000);

    // Enforce spinners view; ignored by MD-based theme in Android >=5, but calendar is REALLY buggy
    // in Android < 5, so let's be sure it never appears (in tablets both spinners and calendar are
    // shown by default)
    picker.setCalendarViewShown(false);

    return dialog;
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.SessionScheduleItemsFragment.java

protected void setupDay(ViewGroup rootView) {
    final long currentTime = getArguments().getLong("currentTime");

    mDay = new Day();

    // Setup data
    for (int i = UIUtils.NUMBER_DAYS; i > 0; i--) {
        if (currentTime >= UIUtils.START_DAYS_IN_MILLIS[i - 1]) {
            mDay.index = (i - 1);/* www.ja  va 2s .c  o  m*/
            break;
        }
    }
    mDay.timeStart = UIUtils.START_DAYS_IN_MILLIS[mDay.index];
    mDay.timeEnd = mDay.timeStart + DateUtils.DAY_IN_MILLIS;
    mDay.loaderUri = CfpContract.Sessions.buildSessionsBetweenDirUri(mDay.timeStart, mDay.timeEnd);

    // Setup views
    mDay.rootView = rootView;

    mDay.scrollView = (ObservableScrollView) mDay.rootView.findViewById(R.id.schedule_items_scroll);

    mDay.scheduleItemsView = (ScheduleItemsLayout) mDay.rootView.findViewById(R.id.schedule_items);
    mDay.nowView = mDay.rootView.findViewById(R.id.schedule_items_now);

    // mDay.blocksView.setDrawingCacheEnabled(true);
    // mDay.blocksView.setAlwaysDrawnWithCacheEnabled(true);

    TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE);
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.BlockScheduleItemsFragment.java

protected void setupDay(ViewGroup rootView) {
    final int position = getArguments().getInt("id");
    final long startMillis = getArguments().getLong("startMillis");

    mDay = new Day();

    // Setup data
    mDay.index = position;//ww w  .  j a va  2s.c  o  m
    mDay.timeStart = startMillis;
    mDay.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS;
    mDay.loaderUri = CfpContract.Blocks.buildBlocksBetweenDirUri(mDay.timeStart, mDay.timeEnd);

    // Setup views
    mDay.rootView = rootView;

    mDay.scrollView = (ObservableScrollView) mDay.rootView.findViewById(R.id.schedule_items_scroll);

    mDay.scheduleItemsView = (ScheduleItemsLayout) mDay.rootView.findViewById(R.id.schedule_items);
    mDay.nowView = mDay.rootView.findViewById(R.id.schedule_items_now);

    // mDay.blocksView.setDrawingCacheEnabled(true);
    // mDay.blocksView.setAlwaysDrawnWithCacheEnabled(true);

    TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE);
    mDay.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS);
}

From source file:com.battlelancer.seriesguide.dataliberation.DataLiberationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_data_liberation, container, false);

    mProgressBar = (ProgressBar) v.findViewById(R.id.progressBarDataLiberation);
    mProgressBar.setVisibility(View.GONE);
    mButtonExport = (Button) v.findViewById(R.id.buttonExport);
    mButtonImport = (Button) v.findViewById(R.id.buttonImport);
    mButtonImportAutoBackup = (Button) v.findViewById(R.id.buttonBackupRestoreAutoBackup);
    mCheckBoxFullDump = (CheckBox) v.findViewById(R.id.checkBoxFullDump);
    mCheckBoxImportWarning = (CheckBox) v.findViewById(R.id.checkBoxImportWarning);

    // display backup path
    TextView backuppath = (TextView) v.findViewById(R.id.textViewBackupPath);
    String path = JsonExportTask.getExportPath(false).toString();
    backuppath.setText(getString(R.string.backup_path) + ": " + path);

    // display current db version
    TextView dbVersion = (TextView) v.findViewById(R.id.textViewBackupDatabaseVersion);
    dbVersion.setText(getString(R.string.backup_version) + ": " + SeriesGuideDatabase.DATABASE_VERSION);

    // display last auto-backup date
    TextView lastAutoBackup = (TextView) v.findViewById(R.id.textViewBackupLastAutoBackup);
    long lastAutoBackupTime = AdvancedSettings.getLastAutoBackupTime(getActivity());
    lastAutoBackup.setText(getString(R.string.last_auto_backup,
            DataLiberationTools.isAutoBackupAvailable()
                    ? DateUtils.getRelativeDateTimeString(getActivity(), lastAutoBackupTime,
                            DateUtils.SECOND_IN_MILLIS, DateUtils.DAY_IN_MILLIS, 0)
                    : "n/a"));

    return v;// ww  w . j a v  a2s  .c  om
}

From source file:com.metinkale.prayerapp.MainIntentService.java

private void handleCalendarIntegration() {
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        Prefs.setCalendar("-1");
        return;//w w  w.  ja  v  a  2s  .  c  o m
    }
    Context context = App.getContext();
    try {
        ContentResolver cr = context.getContentResolver();

        cr.delete(CalendarContract.Events.CONTENT_URI,
                CalendarContract.Events.DESCRIPTION + "=\"com.metinkale.prayer\"", null);

        String id = Prefs.getCalendar();

        if ("-1".equals(id) || (Prefs.getLanguage() == null)) {
            return;
        }
        int year = LocalDate.now().getYear();
        Collection<int[]> days = new ArrayList<>();
        days.addAll(HicriDate.getHolydays(year));
        days.addAll(HicriDate.getHolydays(year + 1));

        int i = 0;
        ContentValues[] events = new ContentValues[days.size()];
        for (int[] date : days) {
            ContentValues event = new ContentValues();

            event.put(CalendarContract.Events.CALENDAR_ID, id);
            event.put(CalendarContract.Events.TITLE, Utils.getHolyday(date[HicriDate.DAY] - 1));
            event.put(CalendarContract.Events.DESCRIPTION, "com.metinkale.prayer");

            ReadableInstant cal = new DateTime(date[HicriDate.GY], date[HicriDate.GM], date[HicriDate.GD], 0, 0,
                    0);

            long dtstart = cal.getMillis();
            long dtend = dtstart + DateUtils.DAY_IN_MILLIS;

            event.put(CalendarContract.Events.DTSTART, dtstart + TimeZone.getDefault().getOffset(dtstart));
            event.put(CalendarContract.Events.DTEND, dtend + TimeZone.getDefault().getOffset(dtend));
            event.put(CalendarContract.Events.EVENT_TIMEZONE, Time.TIMEZONE_UTC);
            event.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED);
            event.put(CalendarContract.Events.ALL_DAY, 1);

            events[i] = event;
            i++;
        }
        cr.bulkInsert(CalendarContract.Events.CONTENT_URI, events);
    } catch (Exception e) {
        Prefs.setCalendar("-1");
        Crashlytics.logException(e);
    }
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.ScheduleFragment.java

/**
 * Update position and visibility of "now" view.
 *///from w  w w.j  a v  a  2s  .  c  om
private boolean updateNowView(boolean forceScroll) {
    final long now = UIUtils.getCurrentTime(getActivity());

    int nowDay = -1;
    for (int i = 0; i < UIUtils.START_DAYS_IN_MILLIS.length; i++) {
        if (now >= UIUtils.START_DAYS_IN_MILLIS[i]
                && now <= (UIUtils.START_DAYS_IN_MILLIS[i] + DateUtils.DAY_IN_MILLIS)) {
            nowDay = i;
            break;
        }
    }

    if (nowDay != -1 && forceScroll) {
        mViewPager.setCurrentItem(nowDay);
        return true;
    }

    return false;
}