Java Code Examples for android.text.format.DateUtils#formatElapsedTime()
The following examples show how to use
android.text.format.DateUtils#formatElapsedTime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicActivity.java From DMAudioStreamer with Apache License 2.0 | 6 votes |
private void setPGTime(int progress) { try { String timeString = "00.00"; int linePG = 0; currentSong = streamingManager.getCurrentAudio(); if (currentSong != null && progress != Long.parseLong(currentSong.getMediaDuration())) { timeString = DateUtils.formatElapsedTime(progress / 1000); Long audioDuration = Long.parseLong(currentSong.getMediaDuration()); linePG = (int) (((progress / 1000) * 100) / audioDuration); } time_progress_bottom.setText(timeString); time_progress_slide.setText(timeString); lineProgress.setLineProgress(linePG); } catch (NumberFormatException e) { e.printStackTrace(); } }
Example 2
Source File: TrackInformation.java From trekarta with GNU General Public License v3.0 | 6 votes |
private void updateTrackInformation(Activity activity, Resources resources) { Track.TrackPoint ftp = mTrack.points.get(0); Track.TrackPoint ltp = mTrack.getLastPoint(); int pointCount = mTrack.points.size(); mPointCountView.setText(resources.getQuantityString(R.plurals.numberOfPoints, pointCount, pointCount)); String distance = StringFormatter.distanceHP(mTrack.getDistance()); mDistanceView.setText(distance); String finish_coords = StringFormatter.coordinates(ltp); mFinishCoordinatesView.setText(finish_coords); Date finishDate = new Date(ltp.time); mFinishDateView.setText(String.format("%s %s", DateFormat.getDateFormat(activity).format(finishDate), DateFormat.getTimeFormat(activity).format(finishDate))); long elapsed = (ltp.time - ftp.time) / 1000; String timeSpan; if (elapsed < 24 * 3600 * 3) { // 3 days timeSpan = DateUtils.formatElapsedTime(elapsed); } else { timeSpan = DateUtils.formatDateRange(activity, ftp.time, ltp.time, DateUtils.FORMAT_ABBREV_MONTH); } mTimeSpanView.setText(timeSpan); }
Example 3
Source File: JobService.java From firebase-jobdispatcher-android with Apache License 2.0 | 6 votes |
/** * Package-private alias for {@link #dump(FileDescriptor, PrintWriter, String[])}. * * <p>The {@link #dump(FileDescriptor, PrintWriter, String[])} method is protected. This * implementation method is marked package-private to facilitate testing. */ @VisibleForTesting final void dumpImpl(PrintWriter writer) { synchronized (runningJobs) { if (runningJobs.isEmpty()) { writer.println("No running jobs"); return; } long now = SystemClock.elapsedRealtime(); writer.println("Running jobs:"); for (int i = 0; i < runningJobs.size(); i++) { JobCallback callback = runningJobs.get(runningJobs.keyAt(i)); // Add sanitized quotes around the tag to make this easier to parse for robots String name = JSONObject.quote(callback.job.getTag()); // Produces strings like "02:30" String duration = DateUtils.formatElapsedTime(MILLISECONDS.toSeconds(now - callback.startedAtElapsed)); writer.println(" * " + name + " has been running for " + duration); } } }
Example 4
Source File: QiscusAudioRecorderView.java From qiscus-sdk-android with Apache License 2.0 | 5 votes |
@Override public void run() { long currentTime = System.currentTimeMillis(); long seconds = (currentTime - startTime) / 1000; String formattedDuration = DateUtils.formatElapsedTime(seconds); textViewDuration.setText(formattedDuration); if (isRecording()) { handler.postDelayed(this, 1000L); } }
Example 5
Source File: Format.java From deagle with Apache License 2.0 | 5 votes |
public static String elapsedTime(final long elapsedSeconds) { if (elapsedSeconds < 100 * 60 * 60) return DateUtils.formatElapsedTime(null, elapsedSeconds); final long hours = elapsedSeconds / 3600, minutes; long seconds = hours % 3600; if (seconds >= 60) { minutes = seconds / 60; seconds = minutes % 60; } else minutes = 0; return String.format((Locale) null, "%1$d:%2$02d:%3$02d", hours, minutes, seconds); }
Example 6
Source File: SpeedFragment.java From JayPS-AndroidApp with MIT License | 5 votes |
private void updateFragment(MyLocation event) { NumberConverter converter = new NumberConverter(); TextView speed = (TextView)getActivity().findViewById(R.id.speed_text); String speedText; if (Units.isPace(event.getUnits())) { speedText = converter.convertSpeedToPace(event.getSpeed()); } else { speedText = converter.convertFloatToString(event.getSpeed(), 1); } speed.setText(speedText); TextView avgSpeed = (TextView)getActivity().findViewById(R.id.avgspeed_text); String avgSpeedText; if (Units.isPace(event.getUnits())) { avgSpeedText = converter.convertSpeedToPace(event.getAverageSpeed()); } else { avgSpeedText = converter.convertFloatToString(event.getAverageSpeed(), 1); } avgSpeed.setText(avgSpeedText); TextView distance = (TextView)getActivity().findViewById(R.id.distance_text); distance.setText(converter.convertFloatToString(event.getDistance(),1)); TextView time = (TextView)getActivity().findViewById(R.id.time_text); String timeText = DateUtils.formatElapsedTime(event.getElapsedTimeSeconds()); time.setText(timeText); //Log.d(TAG, "updateFragment time:" + event.getElapsedTimeSeconds()); }
Example 7
Source File: JobStatus.java From JobSchedulerCompat with Apache License 2.0 | 5 votes |
private String formatRunTime(long runtime, long defaultValue) { if (runtime == defaultValue) { return "none"; } else { long elapsedNow = SystemClock.elapsedRealtime(); long nextRuntime = runtime - elapsedNow; if (nextRuntime > 0) { return DateUtils.formatElapsedTime(nextRuntime / 1000); } else { return "-" + DateUtils.formatElapsedTime(nextRuntime / -1000); } } }
Example 8
Source File: PinnedNoteAdapter.java From science-journal with Apache License 2.0 | 5 votes |
public static String getNoteTimeText(long labelTimestamp, long startTimestamp) { long elapsedTimeSeconds = Math.round((labelTimestamp - startTimestamp) / RunReviewFragment.MILLIS_IN_A_SECOND); if (elapsedTimeSeconds < 0) { // String resource: Localization for negative values? return "-" + DateUtils.formatElapsedTime(-1 * elapsedTimeSeconds); } return DateUtils.formatElapsedTime(elapsedTimeSeconds); }
Example 9
Source File: Track.java From Melophile with Apache License 2.0 | 5 votes |
public String getFormatedDuration() { if (!TextUtils.isEmpty(duration)) { long time = Long.parseLong(duration); return DateUtils.formatElapsedTime(time / 1000); } return null; }
Example 10
Source File: MusicActivity.java From DMAudioStreamer with Apache License 2.0 | 5 votes |
private void setMaxTime() { try { String timeString = DateUtils.formatElapsedTime(Long.parseLong(currentSong.getMediaDuration())); time_total_bottom.setText(timeString); time_total_slide.setText(timeString); } catch (NumberFormatException e) { e.printStackTrace(); } }
Example 11
Source File: DurationUtils.java From imsdk-android with MIT License | 5 votes |
/** * 格式化时长(不足一秒则显示为一秒) * * @param duration duration * @return "MM:SS" or "H:MM:SS" */ public static String format(long duration) { long seconds = duration / 1000; if (seconds == 0) { seconds++; } return DateUtils.formatElapsedTime(seconds); }
Example 12
Source File: TimeFormatUtil.java From Tick with MIT License | 4 votes |
public static String formatTime(long millis) { long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); return DateUtils.formatElapsedTime(new StringBuilder(8), seconds); }
Example 13
Source File: InputPanel.java From deltachat-android with GNU General Public License v3.0 | 4 votes |
private String formatElapsedTime(long ms) { return DateUtils.formatElapsedTime(TimeUnit.MILLISECONDS.toSeconds(ms)) + String.format(".%02d", ((ms/10)%100)); }
Example 14
Source File: TimeFormatUtil.java From timecat with Apache License 2.0 | 4 votes |
public static String formatTime(long millis) { long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); return DateUtils.formatElapsedTime(new StringBuilder(8), seconds); }
Example 15
Source File: TrackDetails.java From Androzic with GNU General Public License v3.0 | 4 votes |
private void updateTrackDetails() { AppCompatActivity activity = (AppCompatActivity) getActivity(); Resources resources = getResources(); activity.getSupportActionBar().setTitle(track.name); View view = getView(); int pointCount = track.getPointCount(); ((TextView) view.findViewById(R.id.point_count)).setText(resources.getQuantityString(R.plurals.numberOfPoints, pointCount, pointCount)); String distance = StringFormatter.distanceH(track.distance); ((TextView) view.findViewById(R.id.distance)).setText(distance); Track.TrackPoint ftp = track.getPoint(0); Track.TrackPoint ltp = track.getLastPoint(); String start_coords = StringFormatter.coordinates(" ", ftp.latitude, ftp.longitude); ((TextView) view.findViewById(R.id.start_coordinates)).setText(start_coords); String finish_coords = StringFormatter.coordinates(" ", ltp.latitude, ltp.longitude); ((TextView) view.findViewById(R.id.finish_coordinates)).setText(finish_coords); Date start_date = new Date(ftp.time); ((TextView) view.findViewById(R.id.start_date)).setText(DateFormat.getDateFormat(activity).format(start_date)+" "+DateFormat.getTimeFormat(activity).format(start_date)); Date finish_date = new Date(ltp.time); ((TextView) view.findViewById(R.id.finish_date)).setText(DateFormat.getDateFormat(activity).format(finish_date)+" "+DateFormat.getTimeFormat(activity).format(finish_date)); long elapsed = (ltp.time - ftp.time) / 1000; String timeSpan; if (elapsed < 24 * 60 * 60 * 3) { timeSpan = DateUtils.formatElapsedTime(elapsed); } else { timeSpan = DateUtils.formatDateRange(activity, ftp.time, ltp.time, DateUtils.FORMAT_ABBREV_MONTH); } ((TextView) view.findViewById(R.id.time_span)).setText(timeSpan); // Gather statistics int segmentCount = 0; double minElevation = Double.MAX_VALUE; double maxElevation = Double.MIN_VALUE; double maxSpeed = 0; MeanValue mv = new MeanValue(); for (Track.TrackSegment segment : track.getSegments()) { Track.TrackPoint ptp = null; if (segment.independent) segmentCount++; for (Track.TrackPoint tp : segment.getPoints()) { if (ptp != null) { double d = Geo.distance(tp.latitude, tp.longitude, ptp.latitude, ptp.longitude); double speed = d / ((tp.time - ptp.time) / 1000); if (speed == Double.POSITIVE_INFINITY) continue; mv.addValue(speed); if (speed > maxSpeed) maxSpeed = speed; } ptp = tp; if (tp.elevation < minElevation && tp.elevation != 0) minElevation = tp.elevation; if (tp.elevation > maxElevation) maxElevation = tp.elevation; } } double averageSpeed = mv.getMeanValue(); ((TextView) view.findViewById(R.id.segment_count)).setText(resources.getQuantityString(R.plurals.numberOfSegments, segmentCount, segmentCount)); ((TextView) view.findViewById(R.id.max_elevation)).setText(StringFormatter.elevationH(maxElevation)); ((TextView) view.findViewById(R.id.min_elevation)).setText(StringFormatter.elevationH(minElevation)); ((TextView) view.findViewById(R.id.max_speed)).setText(String.format(Locale.getDefault(), "%s: %s", resources.getString(R.string.max_speed), StringFormatter.speedH(maxSpeed))); ((TextView) view.findViewById(R.id.average_speed)).setText(String.format(Locale.getDefault(), "%s: %s", resources.getString(R.string.average_speed), StringFormatter.speedH(averageSpeed))); }
Example 16
Source File: NumberConverter.java From JayPS-AndroidApp with MIT License | 4 votes |
public String convertSpeedToPace(float number) { return DateUtils.formatElapsedTime((int) (60 * number)); }
Example 17
Source File: TimeFormatUtil.java From ToDoList with Apache License 2.0 | 4 votes |
public static String formatTime(long millis) { long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); return DateUtils.formatElapsedTime(new StringBuilder(8), seconds); }
Example 18
Source File: MediaUtils.java From EasyPhotos with Apache License 2.0 | 2 votes |
/** * 格式化时长(不足一秒则显示为一秒) * * @param duration duration * @return "MM:SS" or "H:MM:SS" */ public static String format(long duration) { double seconds = duration / 1000.0; return DateUtils.formatElapsedTime((long) (seconds + 0.5)); }