Example usage for android.text.format DateUtils HOUR_IN_MILLIS

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

Introduction

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

Prototype

long HOUR_IN_MILLIS

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

Click Source Link

Usage

From source file:com.androidinspain.deskclock.Utils.java

/**
 * Returns string denoting the timezone hour offset (e.g. GMT -8:00)
 *
 * @param useShortForm Whether to return a short form of the header that rounds to the
 *                     nearest hour and excludes the "GMT" prefix
 *///from  www. ja  v  a 2s. co m
public static String getGMTHourOffset(TimeZone timezone, boolean useShortForm) {
    final int gmtOffset = timezone.getRawOffset();
    final long hour = gmtOffset / DateUtils.HOUR_IN_MILLIS;
    final long min = (Math.abs(gmtOffset) % DateUtils.HOUR_IN_MILLIS) / DateUtils.MINUTE_IN_MILLIS;

    if (useShortForm) {
        return String.format(Locale.ENGLISH, "%+d", hour);
    } else {
        return String.format(Locale.ENGLISH, "GMT %+d:%02d", hour, min);
    }
}

From source file:com.appsimobile.appsii.timezonepicker.TimeZoneData.java

private void indexByOffsets(int idx, TimeZoneInfo tzi) {
    int offsetMillis = tzi.getNowOffsetMillis();
    int index = OFFSET_ARRAY_OFFSET + (int) (offsetMillis / DateUtils.HOUR_IN_MILLIS);
    mHasTimeZonesInHrOffset[index] = true;

    IntList group = mTimeZonesByOffsets.get(index);
    if (group == null) {
        group = new IntList(1);
        mTimeZonesByOffsets.put(index, group);
    }//w  w  w  .ja  v a  2s .  com
    group.add(idx);
}

From source file:com.novoda.downloadmanager.lib.DownloadNotifier.java

/**
 * Return given duration in a human-friendly format. For example, "4
 * minutes" or "1 second". Returns only largest meaningful unit of time,
 * from seconds up to hours./* w  ww  .  j  ava2 s .c o m*/
 */
public CharSequence formatDuration(long millis) {
    final Resources res = mContext.getResources();
    if (millis >= DateUtils.HOUR_IN_MILLIS) {
        final int hours = (int) ((millis + 1800000) / DateUtils.HOUR_IN_MILLIS);
        return res.getQuantityString(R.plurals.dl__duration_hours, hours, hours);
    } else if (millis >= DateUtils.MINUTE_IN_MILLIS) {
        final int minutes = (int) ((millis + 30000) / DateUtils.MINUTE_IN_MILLIS);
        return res.getQuantityString(R.plurals.dl__duration_minutes, minutes, minutes);
    } else {
        final int seconds = (int) ((millis + 500) / DateUtils.SECOND_IN_MILLIS);
        return res.getQuantityString(R.plurals.dl__duration_seconds, seconds, seconds);
    }
}

From source file:com.battlelancer.seriesguide.ui.ShowsFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    StringBuilder selection = new StringBuilder();

    // create temporary copies
    final boolean isFilterFavorites = mIsFilterFavorites;
    final boolean isFilterUnwatched = mIsFilterUnwatched;
    final boolean isFilterUpcoming = mIsFilterUpcoming;
    final boolean isFilterHidden = mIsFilterHidden;

    // restrict to favorites?
    if (isFilterFavorites) {
        selection.append(Shows.FAVORITE).append("=1");
    }/*w w  w .ja  va  2 s . com*/

    final long timeInAnHour = System.currentTimeMillis() + DateUtils.HOUR_IN_MILLIS;

    // restrict to shows with a next episode?
    if (isFilterUnwatched) {
        if (selection.length() != 0) {
            selection.append(" AND ");
        }
        selection.append(Shows.NEXTAIRDATEMS).append("!=").append(DBUtils.UNKNOWN_NEXT_RELEASE_DATE);

        // exclude shows with upcoming next episode
        if (!isFilterUpcoming) {
            selection.append(" AND ").append(Shows.NEXTAIRDATEMS).append("<=").append(timeInAnHour);
        }
    }
    // restrict to shows with an upcoming (yet to air) next episode?
    if (isFilterUpcoming) {
        if (selection.length() != 0) {
            selection.append(" AND ");
        }
        // Display shows upcoming within <limit> days + 1 hour
        int upcomingLimitInDays = AdvancedSettings.getUpcomingLimitInDays(getActivity());
        long latestAirtime = timeInAnHour + upcomingLimitInDays * DateUtils.DAY_IN_MILLIS;

        selection.append(Shows.NEXTAIRDATEMS).append("<=").append(latestAirtime);

        // exclude shows with no upcoming next episode if not filtered for unwatched, too
        if (!isFilterUnwatched) {
            selection.append(" AND ").append(Shows.NEXTAIRDATEMS).append(">=").append(timeInAnHour);
        }
    }

    // special: if hidden filter is disabled, exclude hidden shows
    if (selection.length() != 0) {
        selection.append(" AND ");
    }
    selection.append(Shows.HIDDEN).append(isFilterHidden ? "=1" : "=0");

    // keep unwatched and upcoming shows from becoming stale
    schedulePeriodicDataRefresh(true);

    return new CursorLoader(getActivity(), Shows.CONTENT_URI, ShowsQuery.PROJECTION, selection.toString(), null,
            ShowsDistillationSettings.getSortQuery(mSortOrderId, mIsSortFavoritesFirst, mIsSortIgnoreArticles));
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    fragView = inflater.inflate(R.layout.frag_torrent_list, container, false);

    setupActionModeCallback();/*  w  w  w  .j av  a 2s.c o m*/

    final SwipeRefreshLayoutExtra swipeRefresh = (SwipeRefreshLayoutExtra) fragView
            .findViewById(R.id.swipe_container);
    if (swipeRefresh != null) {
        swipeRefresh.setExtraLayout(R.layout.swipe_layout_extra);

        LastUpdatedInfo lui = getLastUpdatedString();
        if (lui != null) {
            View extraView = swipeRefresh.getExtraView();
            if (extraView != null) {
                TextView tvSwipeText = (TextView) extraView.findViewById(R.id.swipe_text);
                tvSwipeText.setText(lui.s);
            }
        }
        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (sessionInfo == null) {
                    return;
                }
                sessionInfo.addTorrentListReceivedListener(new TorrentListReceivedListener() {

                    @Override
                    public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps,
                            List<?> removedTorrentIDs) {
                        AndroidUtils.runOnUIThread(TorrentListFragment.this, new Runnable() {
                            @Override
                            public void run() {
                                if (getActivity() == null) {
                                    return;
                                }
                                swipeRefresh.setRefreshing(false);
                                LastUpdatedInfo lui = getLastUpdatedString();
                                View extraView = swipeRefresh.getExtraView();
                                if (extraView != null) {
                                    TextView tvSwipeText = (TextView) extraView.findViewById(R.id.swipe_text);
                                    tvSwipeText.setText(lui.s);
                                }
                            }
                        });
                        sessionInfo.removeTorrentListReceivedListener(this);
                    }
                }, false);
                sessionInfo.triggerRefresh(true);
            }
        });
        swipeRefresh.setOnExtraViewVisibilityChange(
                new SwipeRefreshLayoutExtra.OnExtraViewVisibilityChangeListener() {
                    private Handler pullRefreshHandler;

                    @Override
                    public void onExtraViewVisibilityChange(final View view, int visibility) {
                        if (pullRefreshHandler != null) {
                            pullRefreshHandler.removeCallbacksAndMessages(null);
                            pullRefreshHandler = null;
                        }
                        if (visibility != View.VISIBLE) {
                            return;
                        }

                        pullRefreshHandler = new Handler(Looper.getMainLooper());

                        pullRefreshHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                if (getActivity() == null) {
                                    return;
                                }
                                LastUpdatedInfo lui = getLastUpdatedString();
                                if (lui == null) {
                                    return;
                                }
                                TextView tvSwipeText = (TextView) view.findViewById(R.id.swipe_text);
                                tvSwipeText.setText(lui.s);

                                if (pullRefreshHandler != null) {
                                    pullRefreshHandler.postDelayed(this,
                                            lui.sinceMS < DateUtils.MINUTE_IN_MILLIS
                                                    ? DateUtils.SECOND_IN_MILLIS
                                                    : lui.sinceMS < DateUtils.HOUR_IN_MILLIS
                                                            ? DateUtils.MINUTE_IN_MILLIS
                                                            : DateUtils.HOUR_IN_MILLIS);
                                }
                            }
                        }, 0);
                    }
                });
    }

    listview = (RecyclerView) fragView.findViewById(R.id.listTorrents);
    listview.setLayoutManager(new PreCachingLayoutManager(getContext()));
    listview.setAdapter(torrentListAdapter);

    if (AndroidUtils.isTV()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            listview.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
        }
        ((FastScrollRecyclerView) listview).setEnableFastScrolling(false);
        ((FlexibleRecyclerView) listview).setFixedVerticalHeight(AndroidUtilsUI.dpToPx(48));
        listview.setVerticalFadingEdgeEnabled(true);
        listview.setFadingEdgeLength(AndroidUtilsUI.dpToPx((int) (48 * 1.5)));
    }

    filterEditText = (EditText) fragView.findViewById(R.id.filterText);
    filterEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Filter filter = torrentListAdapter.getFilter();
            filter.filter(s);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    setupSideListArea(fragView);

    /** Handy code to watch the states of row 2
     listview.postDelayed(new Runnable() {
     String oldS = "";
            
     @Override public void run() {
            
     String s = (listview.getChildCount() < 3 ? ""
     : AndroidUtils.getStatesString(listview.getChildAt(2).getDrawableState
     ()));
            
     if (!s.equals(oldS)) {
     oldS = s;
     Log.e(TAG, "States of 2: " + s);
     }
            
     listview.postDelayed(this, 500);
     }
     }, 500);
     */

    setHasOptionsMenu(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        onCreateViewHC(fragView);
    }

    if (sideListArea != null) {
        fragView.post(new Runnable() {
            @Override
            public void run() {
                FragmentActivity activity = getActivity();
                if (activity == null) {
                    return;
                }
                Window window = activity.getWindow();
                if (window == null) {
                    return;
                }
                int dpHeight = window.getDecorView().getHeight();
                hideUnselectedSideHeaders = dpHeight < SIDELIST_HIDE_UNSELECTED_HEADERS_MAX_PX;
                expandSideListWidth(sidelistInFocus);
                if (AndroidUtils.DEBUG) {
                    Log.d(TAG, "onAttach: hide? " + hideUnselectedSideHeaders + ";" + dpHeight);
                }
            }
        });
    }

    return fragView;

}

From source file:com.android.deskclock.Utils.java

/**
 * Returns string denoting the timezone hour offset (e.g. GMT -8:00)
 * @param useShortForm Whether to return a short form of the header that rounds to the
 *                     nearest hour and excludes the "GMT" prefix
 *//*w  w w  .  j  a v  a  2  s  .c  o m*/
public static String getGMTHourOffset(TimeZone timezone, boolean useShortForm) {
    final int gmtOffset = timezone.getRawOffset();
    final long hour = gmtOffset / DateUtils.HOUR_IN_MILLIS;
    final long min = (Math.abs(gmtOffset) % DateUtils.HOUR_IN_MILLIS) / DateUtils.MINUTE_IN_MILLIS;

    if (useShortForm) {
        return String.format("%+d", hour);
    } else {
        return String.format("GMT %+d:%02d", hour, min);
    }
}

From source file:org.voidsink.anewjkuapp.utils.AppUtils.java

public static void updateSyncAlarm(Context context, boolean reCreateAlarm) {
    boolean mIsCalendarSyncEnabled = false;
    boolean mIsKusssSyncEnable = false;
    boolean mIsMasterSyncEnabled = ContentResolver.getMasterSyncAutomatically();

    if (mIsMasterSyncEnabled) {
        final Account mAccount = getAccount(context);
        if (mAccount != null) {
            mIsCalendarSyncEnabled = ContentResolver.getSyncAutomatically(mAccount,
                    CalendarContractWrapper.AUTHORITY());
            mIsKusssSyncEnable = ContentResolver.getSyncAutomatically(mAccount, KusssContentContract.AUTHORITY);
        }//from  ww w.j av a 2  s  .c  o m
    }

    Log.d(TAG, String.format("MasterSync=%b, CalendarSync=%b, KusssSync=%b", mIsMasterSyncEnabled,
            mIsCalendarSyncEnabled, mIsKusssSyncEnable));

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, SyncAlarmService.class);
    intent.putExtra(Consts.ARG_UPDATE_CAL, !mIsCalendarSyncEnabled);
    intent.putExtra(Consts.ARG_UPDATE_KUSSS, !mIsKusssSyncEnable);
    intent.putExtra(Consts.ARG_RECREATE_SYNC_ALARM, true);
    intent.putExtra(Consts.SYNC_SHOW_PROGRESS, true);

    // check if pending intent exists
    reCreateAlarm = reCreateAlarm
            || (PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_NO_CREATE) == null);

    // new pending intent
    PendingIntent alarmIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    if (!mIsMasterSyncEnabled || !mIsCalendarSyncEnabled || !mIsKusssSyncEnable) {
        if (reCreateAlarm) {
            long interval = PreferenceWrapper.getSyncInterval(context) * DateUtils.HOUR_IN_MILLIS;

            // synchronize in half an hour
            am.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                    System.currentTimeMillis() + AlarmManager.INTERVAL_HALF_HOUR, interval, alarmIntent);
        }
    } else {
        am.cancel(alarmIntent);
    }
}

From source file:com.vuze.android.remote.fragment.FilesFragment.java

@Override
public void onExtraViewVisibilityChange(final View view, int visibility) {
    if (pullRefreshHandler != null) {
        pullRefreshHandler.removeCallbacksAndMessages(null);
        pullRefreshHandler = null;/*from  ww w .  j  av a2  s .  c  om*/
    }
    if (visibility != View.VISIBLE) {
        return;
    }

    pullRefreshHandler = new Handler(Looper.getMainLooper());
    pullRefreshHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            FragmentActivity activity = getActivity();
            if (activity == null) {
                return;
            }
            long sinceMS = System.currentTimeMillis() - lastUpdated;
            String since = DateUtils.getRelativeDateTimeString(activity, lastUpdated,
                    DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0).toString();
            String s = activity.getResources().getString(R.string.last_updated, since);

            TextView tvSwipeText = (TextView) view.findViewById(R.id.swipe_text);
            tvSwipeText.setText(s);

            if (pullRefreshHandler != null) {
                pullRefreshHandler.postDelayed(this,
                        sinceMS < DateUtils.MINUTE_IN_MILLIS ? DateUtils.SECOND_IN_MILLIS
                                : sinceMS < DateUtils.HOUR_IN_MILLIS ? DateUtils.MINUTE_IN_MILLIS
                                        : DateUtils.HOUR_IN_MILLIS);
            }
        }
    }, 0);
}

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;//ww w . jav  a 2 s  . c o  m
    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;
}