Function to get Progress percentage for ProgressDialog - Android User Interface

Android examples for User Interface:ProgressDialog

Description

Function to get Progress percentage for ProgressDialog

Demo Code


//package com.java2s;

public class Main {
    /**//ww  w  .  ja  v a2 s.  c om
     * Function to get Progress percentage
     * 
     * @param currentDuration
     * @param totalDuration
     */
    public static int getProgressPercentage(long currentDuration,
            long totalDuration) {

        if (totalDuration == 0) {
            return 0;
        }

        Double percentage = (double) 0;

        long currentSeconds = (int) (currentDuration / 1000);
        long totalSeconds = (int) (totalDuration / 1000);

        // calculating percentage
        percentage = (((double) currentSeconds) / totalSeconds) * 100;

        // return percentage
        return percentage.intValue();
    }
}

Related Tutorials