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:com.apptentive.android.sdk.tests.module.engagement.InteractionTest.java

public void testListOfVariousInteractions() {
    Log.e("Running test: testListOfVariousInteractions()\n\n");
    resetDevice();/*www .  j a va  2  s  .c om*/

    String json = FileUtil.loadTextAssetAsString(getTestContext(),
            TEST_DATA_DIR + "testListOfVariousInteractions.json");
    InteractionManager.storeInteractions(getTargetContext(), json);
    Interactions interactions = InteractionManager.loadInteractions(getTargetContext());
    List<Interaction> interactionsForCodePoint = interactions.getInteractionList("complex_criteria");
    assertNotNull("Failed to parse interactions.", interactions);
    Interaction interaction = interactionsForCodePoint.get(0);

    // Conditions are not met yet.
    VersionHistoryStore.updateVersionHistory(getTargetContext(), 0, "1.0",
            Util.currentTimeSeconds() - (DateUtils.DAY_IN_MILLIS / 1000 * 10)); // 10 days ago
    VersionHistoryStore.updateVersionHistory(getTargetContext(), 1, "1.1",
            Util.currentTimeSeconds() - (DateUtils.DAY_IN_MILLIS / 1000 * 8)); //  8 days ago
    VersionHistoryStore.updateVersionHistory(getTargetContext(), 2, "1.2",
            Util.currentTimeSeconds() - (DateUtils.DAY_IN_MILLIS / 1000 * 6)); //  6 days ago
    //CodePointStore.storeCodePointForCurrentAppVersion(getTargetContext(), "app.launch");
    boolean canRun = interaction.canRun(getTargetContext());
    assertFalse(canRun);

    // Allow it to run.
    VersionHistoryStore.updateVersionHistory(getTargetContext(), 4, "2.0",
            Util.currentTimeSeconds() - (DateUtils.DAY_IN_MILLIS / 1000 * 2)); //  2 days ago
    CodePointStore.storeCodePointForCurrentAppVersion(getTargetContext(), "app.launch");
    canRun = interaction.canRun(getTargetContext());
    assertTrue(canRun);

    Log.e("Finished test.");
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Updates or inserts {@code path} into history database.
 *//*  w w  w . j  a v a  2 s  .co  m*/
private void updateDbHistory(Uri path) {
    if (BuildConfig.DEBUG)
        Log.d(CLASSNAME, "updateDbHistory() >> path = " + path);

    Calendar cal = Calendar.getInstance();
    final long beginTodayMillis = cal.getTimeInMillis() - (cal.get(Calendar.HOUR_OF_DAY) * 60 * 60 * 1000
            + cal.get(Calendar.MINUTE) * 60 * 1000 + cal.get(Calendar.SECOND) * 1000);
    if (BuildConfig.DEBUG) {
        Log.d(CLASSNAME, String.format("beginToday = %s (%s)", DbUtils.formatNumber(beginTodayMillis),
                new Date(beginTodayMillis)));
        Log.d(CLASSNAME,
                String.format("endToday = %s (%s)",
                        DbUtils.formatNumber(beginTodayMillis + DateUtils.DAY_IN_MILLIS),
                        new Date(beginTodayMillis + DateUtils.DAY_IN_MILLIS)));
    }

    /*
     * Does the update and returns the number of rows updated.
     */
    long time = new Date().getTime();
    ContentValues values = new ContentValues();
    values.put(HistoryContract.COLUMN_PROVIDER_ID, BaseFileProviderUtils.getProviderId(path.getAuthority()));
    values.put(HistoryContract.COLUMN_FILE_TYPE, BaseFile.FILE_TYPE_DIRECTORY);
    values.put(HistoryContract.COLUMN_URI, path.toString());
    values.put(HistoryContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(time));

    int count = getActivity().getContentResolver().update(HistoryContract.genContentUri(getActivity()), values,
            String.format("%s >= '%s' and %s < '%s' and %s = %s and %s like %s",
                    HistoryContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(beginTodayMillis),
                    HistoryContract.COLUMN_MODIFICATION_TIME,
                    DbUtils.formatNumber(beginTodayMillis + DateUtils.DAY_IN_MILLIS),
                    HistoryContract.COLUMN_PROVIDER_ID,
                    DatabaseUtils.sqlEscapeString(values.getAsString(HistoryContract.COLUMN_PROVIDER_ID)),
                    HistoryContract.COLUMN_URI,
                    DatabaseUtils.sqlEscapeString(values.getAsString(HistoryContract.COLUMN_URI))),
            null);
    if (count <= 0) {
        values.put(HistoryContract.COLUMN_CREATE_TIME, DbUtils.formatNumber(time));
        getActivity().getContentResolver().insert(HistoryContract.genContentUri(getActivity()), values);
    }
}

From source file:com.tct.mail.ui.ConversationListFragment.java

private String getElapseTime(long time) {
    long now = System.currentTimeMillis();
    long elapseTime = now - time;
    String displayTime;/*from   www  . ja v a2s . c  o  m*/
    if (elapseTime < 0) {
        // abnormal time, this may occur when user change system time to a wrong time
        displayTime = (String) DateUtils.getRelativeTimeSpanString(mActivity.getActivityContext(), time);
    } else if (elapseTime < DateUtils.DAY_IN_MILLIS) {
        //within one day
        displayTime = (String) DateUtils.getRelativeTimeSpanString(mActivity.getActivityContext(), time);
        displayTime = mActivity.getActivityContext().getString(R.string.conversation_time_elapse_today) + ", "
                + displayTime;
    } else {
        //beyond one day
        java.text.DateFormat timeFormat = DateFormat.getTimeFormat(mActivity.getActivityContext());
        Date date = new Date(time);
        String dateText = DateUtils.formatDateTime(mActivity.getActivityContext(), time,
                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH);
        displayTime = dateText + ", " + timeFormat.format(date);
    }

    return displayTime;
}

From source file:com.tct.mail.browse.ConversationItemView.java

private String getElapseTime() {
    long time = mHeader.conversation.dateMs;
    long now = System.currentTimeMillis();
    long elapseTime = now - time;
    String displayTime;// w  w w  .j av  a 2 s .  c  om
    if (elapseTime < 0) {
        // abnormal time, this may occur when user change system time to a wrong time
        displayTime = (String) DateUtils.getRelativeTimeSpanString(mContext, time);
    } else if (elapseTime < DateUtils.MINUTE_IN_MILLIS) {
        // within one minute
        displayTime = mContext.getString(R.string.conversation_time_elapse_just_now);
    } else if (elapseTime < DateUtils.HOUR_IN_MILLIS) {
        //with in one hour
        int min = (int) (elapseTime / DateUtils.MINUTE_IN_MILLIS);
        displayTime = String.format(mContext.getString(R.string.conversation_time_elapse_minute), min);
    } else if (elapseTime < DateUtils.DAY_IN_MILLIS) {
        //within one day
        displayTime = (String) DateUtils.getRelativeTimeSpanString(mContext, time);
    } else {
        //beyond one day
        displayTime = (String) DateUtils.getRelativeTimeSpanString(mContext, time);
    }

    return displayTime;
}