List of usage examples for android.text.format DateUtils DAY_IN_MILLIS
long DAY_IN_MILLIS
To view the source code for android.text.format DateUtils DAY_IN_MILLIS.
Click Source Link
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"); }/*ww w . j av a 2 s . c o m*/ 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.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
/** * Raises a notification with a biggest earthquake with each sync * * @param notifyValues data with the biggest recent earthquake *///from ww w. jav a2 s. com private void sendNotification(ContentValues notifyValues) { Context context = getContext(); if (Utilities.getNotificationsPrefs(context) && !Utilities.checkForeground(context)) { //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_lastnotification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DateUtils.DAY_IN_MILLIS) { Intent intent = new Intent(context, DetailActivity.class); double latitude = notifyValues.getAsDouble(EarthquakeColumns.LATITUDE); double longitude = notifyValues.getAsDouble(EarthquakeColumns.LONGITUDE); LatLng latLng = new LatLng(latitude, longitude); String distance = context.getString(R.string.earthquake_distance, LocationUtils.getDistance(latLng, LocationUtils.getLocation(context))); String magnitude = context.getString(R.string.earthquake_magnitude, notifyValues.getAsDouble(EarthquakeColumns.MAG)); String date = Utilities.getRelativeDate(notifyValues.getAsLong(EarthquakeColumns.TIME)); double depth = notifyValues.getAsDouble(EarthquakeColumns.DEPTH); intent.putExtra(Feature.MAGNITUDE, notifyValues.getAsDouble(EarthquakeColumns.MAG)); intent.putExtra(Feature.PLACE, notifyValues.getAsString(EarthquakeColumns.PLACE)); intent.putExtra(Feature.DATE, date); intent.putExtra(Feature.LINK, notifyValues.getAsString(EarthquakeColumns.URL)); intent.putExtra(Feature.LATLNG, latLng); intent.putExtra(Feature.DISTANCE, distance); intent.putExtra(Feature.DEPTH, depth); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, EarthquakeObject.NOTIFICATION_ID_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true) .setContentTitle(context.getString(R.string.earthquake_statistics_largest)) .setContentText(context.getString(R.string.earthquake_magnitude, notifyValues.get(EarthquakeColumns.MAG))) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_info_black_24dp) .setLargeIcon(largeIcon).setTicker(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(notifyValues.get(EarthquakeColumns.PLACE).toString() + "\n" + magnitude + "\n" + context.getString(R.string.earthquake_depth, depth) + "\n" + distance + "\n" + date)) .setGroup(EarthquakeObject.NOTIFICATION_GROUP).setGroupSummary(true); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context); managerCompat.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); //refreshing last sync boolean success = prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).commit(); } } }
From source file:com.stasbar.knowyourself.Utils.java
/** * Generate arrays of short and long weekdays, starting from Sunday */// ww w. jav a2s . c o m private static void generateShortAndLongWeekdaysIfNeeded() { if (sShortWeekdays != null && sLongWeekdays != null && !localeHasChanged()) { // nothing to do return; } final Locale locale = Locale.getDefault(); final SimpleDateFormat shortFormat = new SimpleDateFormat(DATE_FORMAT_SHORT, locale); final SimpleDateFormat longFormat = new SimpleDateFormat(DATE_FORMAT_LONG, locale); sShortWeekdays = new String[DaysOfWeek.DAYS_IN_A_WEEK]; sLongWeekdays = new String[DaysOfWeek.DAYS_IN_A_WEEK]; // Create a date (2014/07/20) that is a Sunday final long aSunday = new GregorianCalendar(2014, Calendar.JULY, 20).getTimeInMillis(); for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final long dayMillis = aSunday + i * DateUtils.DAY_IN_MILLIS; sShortWeekdays[i] = shortFormat.format(new Date(dayMillis)); sLongWeekdays[i] = longFormat.format(new Date(dayMillis)); } // Track the Locale used to generate these weekdays sLocaleUsedForWeekdays = Locale.getDefault(); }
From source file:com.wikitude.phonegap.WikitudePlugin.java
private static int clearCacheFolder(final File dir, final int numDays) { int deletedFiles = 0; if (dir != null && dir.isDirectory()) { try {//from ww w. j av a 2s .c o m for (File child : dir.listFiles()) { //first delete subdirectories recursively if (child.isDirectory()) { deletedFiles += clearCacheFolder(child, numDays); } //then delete the files and subdirectories in this dir //only empty directories can be deleted, so subdirs have been done first if (child.lastModified() < new Date().getTime() - numDays * DateUtils.DAY_IN_MILLIS) { if (child.delete()) { deletedFiles++; } } } } catch (Exception e) { e.printStackTrace(); } } return deletedFiles; }
From source file:com.android.calendar.Event.java
public boolean drawAsAllday() { // Use >= so we'll pick up Exchange allday events return allDay || endMillis - startMillis >= DateUtils.DAY_IN_MILLIS; }
From source file:com.android.deskclock.Utils.java
/** * Generate arrays of short and long weekdays, starting from Sunday */// w w w .jav a 2 s . co m private static void generateShortAndLongWeekdaysIfNeeded() { if (sShortWeekdays != null && sLongWeekdays != null && !localeHasChanged()) { // nothing to do return; } if (sShortWeekdays == null) { sShortWeekdays = new String[DaysOfWeek.DAYS_IN_A_WEEK]; } if (sLongWeekdays == null) { sLongWeekdays = new String[DaysOfWeek.DAYS_IN_A_WEEK]; } final SimpleDateFormat shortFormat = new SimpleDateFormat(DATE_FORMAT_SHORT); final SimpleDateFormat longFormat = new SimpleDateFormat(DATE_FORMAT_LONG); // Create a date (2014/07/20) that is a Sunday final long aSunday = new GregorianCalendar(2014, Calendar.JULY, 20).getTimeInMillis(); for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final long dayMillis = aSunday + i * DateUtils.DAY_IN_MILLIS; sShortWeekdays[i] = shortFormat.format(new Date(dayMillis)); sLongWeekdays[i] = longFormat.format(new Date(dayMillis)); } // Track the Locale used to generate these weekdays sLocaleUsedForWeekdays = Locale.getDefault(); }
From source file:bulat.diet.helper_sport.utils.IabHelper.java
public int isSubscribed() throws JSONException, RemoteException { // Query purchases if (subscriptionsSupported()) { logDebug("Querying owned items, item type: " + "subs"); logDebug("Package name: " + mContext.getPackageName()); boolean verificationFailed = false; String continueToken = null; do {/*from w w w . j a v a 2 s . co m*/ logDebug("Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), "subs", continueToken); int response = getResponseCodeFromBundle(ownedItems); logDebug("Owned items response: " + String.valueOf(response)); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getPurchases() failed: " + getResponseDesc(response)); return response; } if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) { logError("Bundle returned from getPurchases() doesn't contain required fields."); return IABHELPER_BAD_RESPONSE; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems .getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String signature = signatureList.get(i); String sku = ownedSkus.get(i); // if (Security.verifyPurchase(mSignatureBase64, // purchaseData, signature)) { logDebug("Sku is owned: " + sku); Purchase purchase = new Purchase("subs", purchaseData, signature); Date currDate = new Date(); if (sku != null && currDate.getTime() > SaveUtils.getEndPDate(mContext)) { if (sku.equals(PaymentsListActivity.SKU_YEAR)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUNTH)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUNTH_OLD)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_OLD)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_NEW)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_VIP)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_HALFYEAR)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 190 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUUNTH_NEW)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_HALFYEAR_2017)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 190 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUUNTH_2017)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_2017)) { SaveUtils.setEndPDate(purchase.getPurchaseTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } } if (TextUtils.isEmpty(purchase.getToken())) { logWarn("BUG: empty/null token!"); logDebug("Purchase data: " + purchaseData); } // Record ownership and token // inv.addPurchase(purchase); // } // else { // logWarn("Purchase signature verification **FAILED**. Not adding item."); // logDebug(" Purchase data: " + purchaseData); // / logDebug(" Signature: " + signature); // verificationFailed = true; // } } continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN); logDebug("Continuation token: " + continueToken); } while (!TextUtils.isEmpty(continueToken)); return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK; } else { return IABHELPER_UNKNOWN_ERROR; } }
From source file:com.android.calendar.alerts.AlertService.java
/** * Searches the CalendarAlerts table for alarms that should have fired but * have not and then reschedules them. This method can be called at boot * time to restore alarms that may have been lost due to a phone reboot. * * @param cr the ContentResolver/*from w w w .j a v a 2 s . c o m*/ * @param context the Context * @param manager the AlarmManager */ private static final void rescheduleMissedAlarms(ContentResolver cr, Context context, AlarmManagerInterface manager) { // Get all the alerts that have been scheduled but have not fired // and should have fired by now and are not too old. long now = System.currentTimeMillis(); long ancient = now - DateUtils.DAY_IN_MILLIS; String[] projection = new String[] { CalendarContract.CalendarAlerts.ALARM_TIME, }; if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) { //If permission is not granted then just return. Log.d(TAG, "Manifest.permission.READ_CALENDAR is not granted"); return; } // TODO: construct an explicit SQL query so that we can add // "GROUPBY" instead of doing a sort and de-dup Cursor cursor = cr.query(CalendarAlerts.CONTENT_URI, projection, WHERE_RESCHEDULE_MISSED_ALARMS, (new String[] { Long.toString(now), Long.toString(ancient), Long.toString(now) }), SORT_ORDER_ALARMTIME_ASC); if (cursor == null) { return; } if (DEBUG) { Log.d(TAG, "missed alarms found: " + cursor.getCount()); } try { long alarmTime = -1; while (cursor.moveToNext()) { long newAlarmTime = cursor.getLong(0); if (alarmTime != newAlarmTime) { if (DEBUG) { Log.w(TAG, "rescheduling missed alarm. alarmTime: " + newAlarmTime); } AlertUtils.scheduleAlarm(context, manager, newAlarmTime); alarmTime = newAlarmTime; } } } finally { cursor.close(); } }
From source file:bulat.diet.helper_sport.utils.IabHelper.java
public int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException { // Query purchases logDebug("Querying owned items, item type: " + itemType); logDebug("Package name: " + mContext.getPackageName()); boolean verificationFailed = false; String continueToken = null;//from w w w . ja va 2 s. c o m do { logDebug("Calling getPurchases with continuation token: " + continueToken); Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken); int response = getResponseCodeFromBundle(ownedItems); logDebug("Owned items response: " + String.valueOf(response)); if (response != BILLING_RESPONSE_RESULT_OK) { logDebug("getPurchases() failed: " + getResponseDesc(response)); return response; } if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST) || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) { logError("Bundle returned from getPurchases() doesn't contain required fields."); return IABHELPER_BAD_RESPONSE; } ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST); inv.setSkuArray(ownedSkus); for (int i = 0; i < purchaseDataList.size(); ++i) { String purchaseData = purchaseDataList.get(i); String signature = signatureList.get(i); String sku = ownedSkus.get(i); if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) { logDebug("Sku is owned: " + sku); Purchase purchase = new Purchase(itemType, purchaseData, signature); if (TextUtils.isEmpty(purchase.getToken())) { logWarn("BUG: empty/null token!"); logDebug("Purchase data: " + purchaseData); } Date currDate = new Date(); if (sku != null && currDate.getTime() > SaveUtils.getEndPDate(mContext)) { // 0 (purchased), 1 (canceled), or 2 (refunded). if (purchase.getPurchaseState() == 0 || purchase.getPurchaseState() == 2) { if (sku.equals(PaymentsListActivity.SKU_YEAR)) { SaveUtils.setEndPDate(currDate.getTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUNTH)) { SaveUtils.setEndPDate(currDate.getTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUNTH_OLD)) { SaveUtils.setEndPDate(currDate.getTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_OLD)) { SaveUtils.setEndPDate(currDate.getTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_NEW)) { SaveUtils.setEndPDate(currDate.getTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_VIP)) { SaveUtils.setEndPDate(currDate.getTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_HALFYEAR)) { SaveUtils.setEndPDate(currDate.getTime() + 190 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUUNTH_NEW)) { SaveUtils.setEndPDate(currDate.getTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_YEAR_2017)) { SaveUtils.setEndPDate(currDate.getTime() + 367 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_HALFYEAR_2017)) { SaveUtils.setEndPDate(currDate.getTime() + 190 * DateUtils.DAY_IN_MILLIS, mContext); } else if (sku.equals(PaymentsListActivity.SKU_MUUNTH_2017)) { SaveUtils.setEndPDate(currDate.getTime() + 32 * DateUtils.DAY_IN_MILLIS, mContext); } } } // Record ownership and token inv.addPurchase(purchase); } else { logWarn("Purchase signature verification **FAILED**. Not adding item."); logDebug(" Purchase data: " + purchaseData); logDebug(" Signature: " + signature); verificationFailed = true; } } continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN); logDebug("Continuation token: " + continueToken); } while (!TextUtils.isEmpty(continueToken)); return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK; }
From source file:com.tct.mail.ui.AnimatedAdapter.java
private void calcGroupInfo() { mColumnViews.clear();/*from w w w.j a v a2 s .co m*/ mColumnPositions.clear(); ConversationCursor cursor = getConversationCursor(); if (cursor != null && cursor.moveToFirst()) { long morningTime = TimeUtils.getDayStartTime(); long firstMonthTime = TimeUtils.getMonthStartTime(); long yearStartTime = TimeUtils.getYearStartTime(); long now = System.currentTimeMillis(); String afterToday = mContext.getString(R.string.conversation_time_after_today); String today = mContext.getString(R.string.conversation_time_today); String yesterday = mContext.getString(R.string.conversation_time_yesterday); String thisMonth = mContext.getString(R.string.conversation_time_this_month); //TS: tao.gan 2016-4-18 EMAIL BUGFIX_1962268 MOD_S // List<String> timeColumnStrings = new ArrayList<>(cursor.getCount()); List<String> timeColumnStrings = null; if (cursor.getCount() >= 0) { timeColumnStrings = new ArrayList<>(cursor.getCount()); } else { timeColumnStrings = new ArrayList<>(); } //TS: tao.gan 2016-4-18 EMAIL BUGFIX_1962268 MOD_E do { Conversation conversation = cursor.getConversation(); long time = conversation.dateMs; if (time > now) { //time after today timeColumnStrings.add(afterToday); } else if (time > morningTime) { //todady timeColumnStrings.add(today); } else if (time > morningTime - DateUtils.DAY_IN_MILLIS) { //yestoday timeColumnStrings.add(yesterday); } else if (time > firstMonthTime) { //this month timeColumnStrings.add(thisMonth); } else if (time > yearStartTime) { //this year SimpleDateFormat df = new SimpleDateFormat("MMMM"); Date date = new Date(time); timeColumnStrings.add(df.format(date)); } else { //beyond this year SimpleDateFormat df = new SimpleDateFormat("MMMM yyyy"); Date date = new Date(time); timeColumnStrings.add(df.format(date)); } } while (cursor.moveToNext()); String lastColumn = ""; int count = 0; for (String timeColumn : timeColumnStrings) { int startPosition = mSpecialViews.size() + mHeaders.size() + mColumnViews.size() + count; if (!timeColumn.equals(lastColumn)) { lastColumn = timeColumn; ConversationTimeColumnView conversationTimeColumnView = new ConversationTimeColumnView(mContext, startPosition); mColumnViews.put(startPosition, conversationTimeColumnView); mColumnPositions.add(startPosition); conversationTimeColumnView.setTitle(timeColumn); } count++; } } }