List of usage examples for android.text.format DateUtils SECOND_IN_MILLIS
long SECOND_IN_MILLIS
To view the source code for android.text.format DateUtils SECOND_IN_MILLIS.
Click Source Link
From source file:com.bubblegum.traceratops.app.ui.adapters.plugins.AbsAdapterPlugin.java
private String systemTimeInMillisToSystemDateFormat(Context context, long millis) { return DateUtils.getRelativeDateTimeString(context, millis, DateUtils.SECOND_IN_MILLIS, 2 * DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString(); }
From source file:net.simonvt.cathode.ui.fragment.WatchedShowsFragment.java
@Override public Loader<SimpleCursor> onCreateLoader(int i, Bundle bundle) { final Uri contentUri = Shows.SHOWS_WATCHED; SimpleCursorLoader cl = new SimpleCursorLoader(getActivity(), contentUri, ShowsWithNextAdapter.PROJECTION, null, null, sortBy.getSortOrder()); cl.setUpdateThrottle(2 * DateUtils.SECOND_IN_MILLIS); return cl;//from w w w .ja va 2s.c o m }
From source file:com.battlelancer.seriesguide.getglueapi.GetGlueAuthActivity.java
/** * Tries to obtain new tokens from GetGlue using the given auth code. Returns true if * successful, returns false and clears any existing tokens if failing. *///from www . j ava2 s.c om public static boolean fetchAndStoreTokens(Context context, String authCode) { Resources resources = context.getResources(); OAuthAccessTokenResponse response = null; Timber.d("Building OAuth 2.0 token request..."); try { response = GetGlue.getAccessTokenResponse(BuildConfig.TVTAG_CLIENT_ID, BuildConfig.TVTAG_CLIENT_SECRET, GetGlueCheckin.OAUTH_CALLBACK_URL, authCode); } catch (OAuthSystemException | OAuthProblemException e) { response = null; Timber.e(e, "Getting access token failed"); } if (response != null) { Timber.d("Storing received OAuth 2.0 tokens..."); long expiresIn = response.getExpiresIn(); long expirationDate = System.currentTimeMillis() + expiresIn * DateUtils.SECOND_IN_MILLIS; PreferenceManager.getDefaultSharedPreferences(context).edit() .putString(GetGlueSettings.KEY_AUTH_TOKEN, response.getAccessToken()) .putLong(GetGlueSettings.KEY_AUTH_EXPIRATION, expirationDate) .putString(GetGlueSettings.KEY_REFRESH_TOKEN, response.getRefreshToken()).commit(); return true; } else { Timber.d("Failed, purging OAuth 2.0 tokens..."); GetGlueSettings.clearTokens(context); return false; } }
From source file:net.niyonkuru.koodroid.ui.AccountFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { switch (id) { case PLAN_TOKEN: { final Uri uri = Plans.buildPlanUri(getSubscriber()); CursorLoader loader = new CursorLoader(mContext, uri, PlansQuery.PROJECTION, null, null, null); loader.setUpdateThrottle(DateUtils.SECOND_IN_MILLIS); return loader; }/* ww w. ja va 2 s.c o m*/ case ADDONS_TOKEN: { final Uri uri = Plans.buildAddonsUri(getSubscriber()); CursorLoader loader = new CursorLoader(mContext, uri, AddonsQuery.PROJECTION, null, null, Addons.DEFAULT_SORT); loader.setUpdateThrottle(DateUtils.SECOND_IN_MILLIS); return loader; } } return null; }
From source file:net.simonvt.cathode.ui.fragment.TrendingMoviesFragment.java
@Override public Loader<SimpleCursor> onCreateLoader(int i, Bundle bundle) { SimpleCursorLoader loader = new SimpleCursorLoader(getActivity(), Movies.TRENDING, null, MovieColumns.NEEDS_SYNC + "=0", null, sortBy.getSortOrder()); loader.setUpdateThrottle(2 * DateUtils.SECOND_IN_MILLIS); return loader; }
From source file:com.nadmm.airports.LocationListFragmentBase.java
protected void startLocationUpdates() { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30 * DateUtils.SECOND_IN_MILLIS, 0.5f * GeoUtils.METERS_PER_STATUTE_MILE, this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean useGps = prefs.getBoolean(PreferencesActivity.KEY_LOCATION_USE_GPS, false); if (useGps) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30 * DateUtils.SECOND_IN_MILLIS, 0.5f * GeoUtils.METERS_PER_STATUTE_MILE, this); }//from w w w .ja va2 s.com } else if (!mPermissionDenied) { if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) { Snackbar.make(getView(), "FlightIntel needs access to device's location.", Snackbar.LENGTH_INDEFINITE).setAction(android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSION_REQUEST_FINE_LOCATION); } }).show(); } else { requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSION_REQUEST_FINE_LOCATION); } } }
From source file:com.battlelancer.seriesguide.ui.BaseActivity.java
/** * Schedule an update for the given show. Might not run if this show was just updated. Execution * is also delayed so it won't reduce UI setup performance (= you can run this in {@link * #onCreate(android.os.Bundle)}).//from w w w .j av a2s . co m * * <p> See {@link com.battlelancer.seriesguide.sync.SgSyncAdapter#requestSyncIfTime(android.content.Context, * int)}. */ protected void updateShowDelayed(final int showTvdbId) { if (mHandler == null) { mHandler = new Handler(); } // delay sync request to avoid slowing down UI final Context context = getApplicationContext(); mUpdateShowRunnable = new Runnable() { @Override public void run() { SgSyncAdapter.requestSyncIfTime(context, showTvdbId); } }; mHandler.postDelayed(mUpdateShowRunnable, DateUtils.SECOND_IN_MILLIS); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.PlusStreamRowViewBinder.java
public static void bindActivityView(final View rootView, Activity activity, ImageLoader imageLoader, boolean singleSourceMode) { // Prepare view holder. ViewHolder tempViews = (ViewHolder) rootView.getTag(); final ViewHolder views; if (tempViews != null) { views = tempViews;//www . j a va 2s . c o m } else { views = new ViewHolder(); rootView.setTag(views); // Author and metadata box views.authorContainer = rootView.findViewById(R.id.stream_author_container); views.userImage = (ImageView) rootView.findViewById(R.id.stream_user_image); views.userName = (TextView) rootView.findViewById(R.id.stream_user_name); views.time = (TextView) rootView.findViewById(R.id.stream_time); // Author's content views.content = (TextView) rootView.findViewById(R.id.stream_content); // Original share box views.originalContainer = rootView.findViewById(R.id.stream_original_container); views.originalAuthor = (TextView) rootView.findViewById(R.id.stream_original_author); views.originalContent = (TextView) rootView.findViewById(R.id.stream_original_content); // Media box views.mediaContainer = rootView.findViewById(R.id.stream_media_container); views.mediaBackground = (ImageView) rootView.findViewById(R.id.stream_media_background); views.mediaOverlay = (ImageView) rootView.findViewById(R.id.stream_media_overlay); views.mediaTitle = (TextView) rootView.findViewById(R.id.stream_media_title); views.mediaSubtitle = (TextView) rootView.findViewById(R.id.stream_media_subtitle); // Interactions box views.interactionsContainer = rootView.findViewById(R.id.stream_interactions_container); views.plusOnes = (TextView) rootView.findViewById(R.id.stream_plus_ones); views.shares = (TextView) rootView.findViewById(R.id.stream_shares); views.comments = (TextView) rootView.findViewById(R.id.stream_comments); } final Context context = rootView.getContext(); final Resources res = context.getResources(); // Determine if this is a reshare (affects how activity fields are to be interpreted). Activity.PlusObject.Actor originalAuthor = activity.getObject().getActor(); boolean isReshare = "share".equals(activity.getVerb()) && originalAuthor != null; // Author and metadata box views.authorContainer.setVisibility(singleSourceMode ? View.GONE : View.VISIBLE); views.userName.setText(activity.getActor().getDisplayName()); // Find user profile image url String userImageUrl = null; if (activity.getActor().getImage() != null) { userImageUrl = activity.getActor().getImage().getUrl(); } // Load image from network in background thread using Volley library imageLoader.get(userImageUrl, views.userImage, PLACEHOLDER_USER_IMAGE); long thenUTC = activity.getUpdated().getValue() + activity.getUpdated().getTimeZoneShift() * 60000; views.time.setText(DateUtils.getRelativeTimeSpanString(thenUTC, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_RELATIVE)); // Author's additional content String selfContent = isReshare ? activity.getAnnotation() : activity.getObject().getContent(); views.content.setMaxLines(singleSourceMode ? 1000 : 5); if (!TextUtils.isEmpty(selfContent)) { views.content.setVisibility(View.VISIBLE); views.content.setText(Html.fromHtml(selfContent)); } else { views.content.setVisibility(View.GONE); } // Original share box if (isReshare) { views.originalContainer.setVisibility(View.VISIBLE); // Set original author text, highlight author name final String author = res.getString(R.string.stream_originally_shared, originalAuthor.getDisplayName()); final SpannableStringBuilder spannableAuthor = new SpannableStringBuilder(author); spannableAuthor.setSpan(new StyleSpan(Typeface.BOLD), author.length() - originalAuthor.getDisplayName().length(), author.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); views.originalAuthor.setText(spannableAuthor, TextView.BufferType.SPANNABLE); String originalContent = activity.getObject().getContent(); views.originalContent.setMaxLines(singleSourceMode ? 1000 : 3); if (!TextUtils.isEmpty(originalContent)) { views.originalContent.setVisibility(View.VISIBLE); views.originalContent.setText(Html.fromHtml(originalContent)); } else { views.originalContent.setVisibility(View.GONE); } } else { views.originalContainer.setVisibility(View.GONE); } // Media box // Set media content. List<Activity.PlusObject.Attachments> attachments = activity.getObject().getAttachments(); if (attachments != null && attachments.size() > 0) { Activity.PlusObject.Attachments attachment = attachments.get(0); String objectType = attachment.getObjectType(); String imageUrl = attachment.getImage() != null ? attachment.getImage().getUrl() : null; if (imageUrl == null && attachment.getThumbnails() != null && attachment.getThumbnails().size() > 0) { Thumbnails thumb = attachment.getThumbnails().get(0); imageUrl = thumb.getImage() != null ? thumb.getImage().getUrl() : null; } // Load image from network in background thread using Volley library imageLoader.get(imageUrl, views.mediaBackground, PLACEHOLDER_MEDIA_IMAGE); boolean overlayStyle = false; views.mediaOverlay.setImageDrawable(null); if (("photo".equals(objectType) || "video".equals(objectType) || "album".equals(objectType)) && !TextUtils.isEmpty(imageUrl)) { overlayStyle = true; views.mediaOverlay .setImageResource("video".equals(objectType) ? R.drawable.ic_stream_media_overlay_video : R.drawable.ic_stream_media_overlay_photo); } else if ("article".equals(objectType) || "event".equals(objectType)) { overlayStyle = false; views.mediaTitle.setText(attachment.getDisplayName()); if (!TextUtils.isEmpty(attachment.getUrl())) { Uri uri = Uri.parse(attachment.getUrl()); views.mediaSubtitle.setText(uri.getHost()); } else { views.mediaSubtitle.setText(""); } } views.mediaContainer.setVisibility(View.VISIBLE); views.mediaContainer.setBackgroundResource( overlayStyle ? R.color.plus_stream_media_background : android.R.color.black); if (overlayStyle) { views.mediaBackground.clearColorFilter(); } else { views.mediaBackground.setColorFilter(res.getColor(R.color.plus_media_item_tint)); } views.mediaOverlay.setVisibility(overlayStyle ? View.VISIBLE : View.GONE); views.mediaTitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE); views.mediaSubtitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE); } else { views.mediaContainer.setVisibility(View.GONE); views.mediaBackground.setImageDrawable(null); views.mediaOverlay.setImageDrawable(null); } // Interactions box final int plusOneCount = (activity.getObject().getPlusoners() != null) ? activity.getObject().getPlusoners().getTotalItems().intValue() : 0; if (plusOneCount > 0) { views.plusOnes.setVisibility(View.VISIBLE); views.plusOnes.setText(getPlusOneString(plusOneCount)); } else { views.plusOnes.setVisibility(View.GONE); } final int commentCount = (activity.getObject().getReplies() != null) ? activity.getObject().getReplies().getTotalItems().intValue() : 0; if (commentCount > 0) { views.comments.setVisibility(View.VISIBLE); views.comments.setText(Integer.toString(commentCount)); } else { views.comments.setVisibility(View.GONE); } final int resharerCount = (activity.getObject().getResharers() != null) ? activity.getObject().getResharers().getTotalItems().intValue() : 0; if (resharerCount > 0) { views.shares.setVisibility(View.VISIBLE); views.shares.setText(Integer.toString(resharerCount)); } else { views.shares.setVisibility(View.GONE); } views.interactionsContainer.setVisibility( (plusOneCount > 0 || commentCount > 0 || resharerCount > 0) ? View.VISIBLE : View.GONE); }
From source file:com.owncloud.android.utils.DisplayUtils.java
/** * calculates the relative time string based on the given modificaion timestamp. * * @param context the app's context/*from www. j a v a2 s . c o m*/ * @param modificationTimestamp the UNIX timestamp of the file modification time. * @return a relative time string */ public static CharSequence getRelativeTimestamp(Context context, long modificationTimestamp) { return getRelativeDateTimeString(context, modificationTimestamp, DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); }
From source file:de.badaix.snapcast.ClientSettingsFragment.java
public void update() { if (client == null) return;/* w ww . java 2s. c o m*/ prefName.setSummary(client.getConfig().getName()); prefName.setText(client.getConfig().getName()); prefMac.setSummary(client.getHost().getMac()); prefIp.setSummary(client.getHost().getIp()); prefHost.setSummary(client.getHost().getName()); prefOS.setSummary(client.getHost().getOs() + "@" + client.getHost().getArch()); prefVersion.setSummary(client.getSnapclient().getVersion()); String lastSeen = getText(R.string.online).toString(); if (!client.isConnected()) { long lastSeenTs = Math.min(client.getLastSeen().getSec() * 1000, System.currentTimeMillis()); lastSeen = DateUtils .getRelativeTimeSpanString(lastSeenTs, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS) .toString(); } prefLastSeen.setSummary(lastSeen); prefLatency.setSummary(client.getConfig().getLatency() + "ms"); prefLatency.setText(client.getConfig().getLatency() + ""); }