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.ferjuarez.androidthingsdemo.PhotoEntryAdapter.java
@Override protected void populateViewHolder(DoorbellEntryViewHolder viewHolder, PhotoEntry model, int position) { // Display the timestamp if (model != null && model.getTimestamp() != null) { CharSequence prettyTime = DateUtils.getRelativeDateTimeString(mApplicationContext, model.getTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); viewHolder.time.setText(prettyTime); // Display the image if (model.getThumbnail() != null) { // Decode image data encoded by the Cloud Vision library byte[] imageBytes = Base64.decode(model.getThumbnail(), Base64.NO_WRAP | Base64.URL_SAFE); Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); if (bitmap != null) { viewHolder.image.setImageBitmap(bitmap); } else { Drawable placeholder = ContextCompat.getDrawable(mApplicationContext, R.mipmap.ic_launcher); viewHolder.image.setImageDrawable(placeholder); }// ww w . jav a 2s.c o m } } // Display the metadata /*if (model.getAnnotations() != null) { ArrayList<String> keywords = new ArrayList<>(model.getAnnotations().keySet()); int limit = Math.min(keywords.size(), 3); viewHolder.metadata.setText(TextUtils.join("\n", keywords.subList(0, limit))); } else { viewHolder.metadata.setText("no annotations yet"); }*/ }
From source file:com.example.androidthings.doorbell.DoorbellEntryAdapter.java
@Override protected void populateViewHolder(DoorbellEntryViewHolder viewHolder, DoorbellEntry model, int position) { // Display the timestamp CharSequence prettyTime = DateUtils.getRelativeDateTimeString(mApplicationContext, model.getTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); viewHolder.time.setText(prettyTime); // Display the image if (model.getImage() != null) { // Decode image data encoded by the Cloud Vision library byte[] imageBytes = Base64.decode(model.getImage(), Base64.NO_WRAP | Base64.URL_SAFE); Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); if (bitmap != null) { viewHolder.image.setImageBitmap(bitmap); } else {//from w w w.ja v a 2 s . com Drawable placeholder = ContextCompat.getDrawable(mApplicationContext, R.drawable.ic_image); viewHolder.image.setImageDrawable(placeholder); } } // Display the metadata if (model.getAnnotations() != null) { ArrayList<String> keywords = new ArrayList<>(model.getAnnotations().keySet()); int limit = Math.min(keywords.size(), 3); viewHolder.metadata.setText(TextUtils.join("\n", keywords.subList(0, limit))); } else { viewHolder.metadata.setText("no annotations yet"); } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;//w ww . j ava 2 s .c o m long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a"); /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "ferries_terminal_sailing_space" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.SECOND_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(TERMINAL_SAILING_SPACE_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONArray array = new JSONArray(jsonFile); List<ContentValues> terminal = new ArrayList<ContentValues>(); int numItems = array.length(); for (int j = 0; j < numItems; j++) { JSONObject item = array.getJSONObject(j); ContentValues sailingSpaceValues = new ContentValues(); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ID, item.getInt("TerminalID")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_NAME, item.getString("TerminalName")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ABBREV, item.getString("TerminalAbbrev")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_DEPARTING_SPACES, item.getString("DepartingSpaces")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_LAST_UPDATED, dateFormat.format(new Date(System.currentTimeMillis()))); if (starred.contains(item.getInt("TerminalID"))) { sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_IS_STARRED, 1); } terminal.add(sailingSpaceValues); } // Purge existing terminal sailing space items covered by incoming data resolver.delete(FerriesTerminalSailingSpace.CONTENT_URI, null, null); // Bulk insert all the new terminal sailing space items resolver.bulkInsert(FerriesTerminalSailingSpace.CONTENT_URI, terminal.toArray(new ContentValues[terminal.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "ferries_terminal_sailing_space" }); responseString = "OK"; } catch (Exception e) { Log.e(TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent .setAction("gov.wa.wsdot.android.wsdot.intent.action.FERRIES_TERMINAL_SAILING_SPACE_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:com.licenta.android.licenseapp.alarm.AlarmFragment.java
@Nullable @Override/* w w w .j a v a 2s . co m*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_alarm, container, false); mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mAlarmFab = (FloatingActionButton) rootView.findViewById(R.id.alarm_fab); mAlarmFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleAlarm(); } }); setUpAlarmFab(); FloatingActionButton safeFab = (FloatingActionButton) rootView.findViewById(R.id.safe_fab); safeFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCountDownTimer.onFinish(); FacebookUtils.printKeyHash(getActivity()); } }); mTimerText = (TextView) rootView.findViewById(R.id.timer); final long futureTime = Long.parseLong(mPrefs.getString("repeat_interval", "0")); mCountDownTimer = new CountDownTimer(futureTime * DateUtils.MINUTE_IN_MILLIS, DateUtils.SECOND_IN_MILLIS) { public void onTick(long millisUntilFinished) { mTimerText.setText(new SimpleDateFormat("mm:ss").format(new Date(millisUntilFinished))); } public void onFinish() { mTimerText.setText(R.string.timer_default); } }; return rootView; }
From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.BulletinFragment.java
@Override public void onResume() { super.onResume(); clearNewNewsItems();// ww w.ja v a2 s . c o m mHandler.postDelayed(mUpdateTimeRunnable, 60 * DateUtils.SECOND_IN_MILLIS); getLoaderManager().restartLoader(NewsQuery._TOKEN, null, this); getActivity().getContentResolver().registerContentObserver(News.CONTENT_URI, true, mNewsChangesObserver); }
From source file:net.niyonkuru.koodroid.ui.DataDetailFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String dataUsage = getResources().getString(R.string.parser_usage_service_data); CursorLoader loader = new CursorLoader(mContext, Subscribers.buildUsagesUri(getSubscriber()), UsagesQuery.PROJECTION, Usages.USAGE_SERVICE + "='" + dataUsage + "'", null, Usages.DEFAULT_SORT); loader.setUpdateThrottle(DateUtils.SECOND_IN_MILLIS); return loader; }
From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.TwitterSearchFragment.java
@Override public void onResume() { super.onResume(); mHandler.postDelayed(mUpdateTimeRunnable, 60 * DateUtils.SECOND_IN_MILLIS); mHandler.postDelayed(mSyncRunnable, 5 * 60 * DateUtils.SECOND_IN_MILLIS); getLoaderManager().restartLoader(TwitterSearchQuery._TOKEN, null, this); getActivity().getContentResolver().registerContentObserver(Tweets.CONTENT_URI, true, mTweetsChangesObserver);//from ww w . j a v a2 s. c om }
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;/*from ww w. ja v a 2 s . c o m*/ }
From source file:com.chalmers.feedlr.adapter.FeedAdapter.java
@Override public void bindView(View v, Context context, Cursor c) { super.bindView(v, context, c); // Holds the views, so that a recycled view does not have to find its // XML view// w w w.j a v a 2 s . c o m ViewHolder viewHolder = (ViewHolder) v.getTag(); // Remove the recycled profile picture viewHolder.profilePicture.setVisibility(View.INVISIBLE); // Get user id int colNumUserId = c.getColumnIndex(DatabaseHelper.ITEM_COLUMN_USER_ID); Cursor cursor = db.getUser(c.getInt(colNumUserId) + ""); cursor.moveToFirst(); // Set source image int colNumSource = cursor.getColumnIndex(DatabaseHelper.USER_COLUMN_SOURCE); if (cursor.getString(colNumSource).equals("facebook")) { viewHolder.source.setBackgroundResource(R.drawable.source_facebook); } else { viewHolder.source.setBackgroundResource(R.drawable.source_twitter); } // Display profile picture int colNumURL = cursor.getColumnIndex(DatabaseHelper.USER_COLUMN_IMGURL); String imgURL = cursor.getString(colNumURL); viewHolder.profilePicture.setTag(numberOfViews++); new DownloadImageTask(viewHolder.profilePicture).execute(imgURL); // Display username int colNumUsername = cursor.getColumnIndex(DatabaseHelper.USER_COLUMN_USERNAME); if (cursor.getString(colNumUsername).length() > 18) { viewHolder.author.setTextSize(16); } viewHolder.author.setText(cursor.getString(colNumUsername)); // Display timestamp int colNumTimestamp = c.getColumnIndex(DatabaseHelper.ITEM_COLUMN_TIMESTAMP); Date timestampDate = new Date(c.getLong(colNumTimestamp)); String parsedTimestamp = DateUtils.getRelativeDateTimeString(context, timestampDate.getTime(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0).toString(); viewHolder.timestamp.setText(stripTimestamp(parsedTimestamp)); }
From source file:net.simonvt.cathode.ui.fragment.WatchedMoviesFragment.java
@Override public Loader<SimpleCursor> onCreateLoader(int i, Bundle bundle) { SimpleCursorLoader loader = new SimpleCursorLoader(getActivity(), Movies.MOVIES, null, MovieColumns.WATCHED + "=1 AND " + MovieColumns.NEEDS_SYNC + "=0", null, sortBy.getSortOrder()); loader.setUpdateThrottle(2 * DateUtils.SECOND_IN_MILLIS); return loader; }