Package com.brightcove.player.network
Class DownloadStatus
- java.lang.Object
-
- com.brightcove.player.network.DownloadStatus
-
- All Implemented Interfaces:
android.os.Parcelable
public class DownloadStatus extends java.lang.Object implements android.os.Parcelable
Download status describes the current status of a download request.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DownloadStatus.ReasonCode
The list of possible reasons code that will be set whenDownloadStatus.StatusCode
is eitherSTATUS_RETRY
orSTATUS_FAILED
.static interface
DownloadStatus.StatusCode
The list of possible status values forDownloadManager.Request
.
-
Field Summary
Fields Modifier and Type Field Description static android.os.Parcelable.Creator<DownloadStatus>
CREATOR
Provides a creator field as required by theParcelable
contract.static int
ERROR_CANNOT_RESUME
The download has failed because some possibly transient error occurred but prevents resuming the download.static int
ERROR_DEVICE_NOT_FOUND
The download has failed because no external storage device was found.static int
ERROR_FILE_ALREADY_EXISTS
The download has failed because the requested destination file already exists.static int
ERROR_FILE_ERROR
The download has failed because of storage issue which doesn't fit under any other error code.static int
ERROR_HTTP_DATA_ERROR
The download has failed because an error occurred while receiving or processing data at the HTTP level.static int
ERROR_INSUFFICIENT_SPACE
The download has failed because there was insufficient storage space.static int
ERROR_NONE
There are no errors in the download request.static int
ERROR_TOO_MANY_REDIRECTS
The download has failed because there were too many redirects.static int
ERROR_UNHANDLED_HTTP_CODE
The download has failed because an HTTP code was received that cannot be handled.static int
ERROR_UNKNOWN
The download has failed with an error that doesn't fit under any other error code.static int
PAUSED_QUEUED_FOR_WIFI
The download exceeds a size limit for downloads over the mobile network and the download manager is waiting for a Wi-Fi connection to proceed.static int
PAUSED_UNKNOWN
The download is paused for some other reason.static int
PAUSED_WAITING_FOR_NETWORK
The download is waiting for network connectivity to proceed.static int
PAUSED_WAITING_TO_RETRY
The download is paused because some network error occurred and the download manager is waiting before retrying the request.static int
STATUS_CANCELLING
Status ofDownloadManager.Request
that is being removed before the download is complete.static int
STATUS_COMPLETE
Status ofDownloadManager.Request
that has successfully downloaded.static int
STATUS_DELETING
Status ofDownloadManager.Request
that is being removed after the download is complete.static int
STATUS_DOWNLOADING
Status ofDownloadManager.Request
that is currently being downloaded.static int
STATUS_FAILED
Status ofDownloadManager.Request
that has failed (and will not be retried).static int
STATUS_NOT_QUEUED
Status ofDownloadManager.Request
that has been not queued for download.static int
STATUS_PAUSED
Status ofDownloadManager.Request
that has been paused explicitly.static int
STATUS_PENDING
Status ofDownloadManager.Request
is waiting to start.static int
STATUS_QUEUEING
Status ofDownloadManager.Request
that is being queued with theDownloadManager
service.static int
STATUS_RETRY
Status ofDownloadManager.Request
that is currently waiting to retry or resume.
-
Constructor Summary
Constructors Constructor Description DownloadStatus()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DownloadStatus
createForInvalidDownloadsFile()
Creates a newDownloadStatus
instance with error specifying that the DownloadsFile is invalid.int
describeContents()
boolean
equals(java.lang.Object o)
long
getActualSize()
Gets the actual total size of the file as number of bytes.long
getBytesDownloaded()
Gets the total number of bytes downloaded so far.int
getCode()
Gets the status code of the download request.long
getEstimatedSize()
Gets the estimated total size of the file as number of bytes.long
getMaxSize()
Gets the maximum size of the file as number of bytes by comparingactualSize
andestimatedSize
double
getProgress()
Calculates the download progress as percentage value.int
getReason()
Gets the reason code of the download request, if any.int
getReasonMessage()
Converts the current status code the string resourced identifier that explains the status.int
getStatusMessage()
Converts the current status code to a string resource identifier that explains status.long
getTime()
Gets the date and time when the status changed as number of milliseconds since January 1, 1970, 00:00:00 GMT.int
hashCode()
boolean
isMarkedForDeletion()
Checks if the status indicates the download is currently marked for deletion.static int
toReasonMessage(int reason)
Converts the given reason code to a string resource identifier that explains the reason.static int
toStatusMessage(int code)
Converts the given status code to a string resource identifier that explains the status.java.lang.String
toString()
void
writeToParcel(android.os.Parcel dest, int flags)
-
-
-
Field Detail
-
STATUS_PAUSED
public static final int STATUS_PAUSED
Status ofDownloadManager.Request
that has been paused explicitly.- See Also:
- Constant Field Values
-
STATUS_DELETING
public static final int STATUS_DELETING
Status ofDownloadManager.Request
that is being removed after the download is complete.- See Also:
- Constant Field Values
-
STATUS_CANCELLING
public static final int STATUS_CANCELLING
Status ofDownloadManager.Request
that is being removed before the download is complete.- See Also:
- Constant Field Values
-
STATUS_QUEUEING
public static final int STATUS_QUEUEING
Status ofDownloadManager.Request
that is being queued with theDownloadManager
service.- See Also:
- Constant Field Values
-
STATUS_NOT_QUEUED
public static final int STATUS_NOT_QUEUED
Status ofDownloadManager.Request
that has been not queued for download.- See Also:
- Constant Field Values
-
STATUS_PENDING
public static final int STATUS_PENDING
Status ofDownloadManager.Request
is waiting to start.- See Also:
- Constant Field Values
-
STATUS_DOWNLOADING
public static final int STATUS_DOWNLOADING
Status ofDownloadManager.Request
that is currently being downloaded.- See Also:
- Constant Field Values
-
STATUS_RETRY
public static final int STATUS_RETRY
Status ofDownloadManager.Request
that is currently waiting to retry or resume.- See Also:
- Constant Field Values
-
STATUS_FAILED
public static final int STATUS_FAILED
Status ofDownloadManager.Request
that has failed (and will not be retried).- See Also:
- Constant Field Values
-
STATUS_COMPLETE
public static final int STATUS_COMPLETE
Status ofDownloadManager.Request
that has successfully downloaded.- See Also:
- Constant Field Values
-
ERROR_NONE
public static final int ERROR_NONE
There are no errors in the download request.- See Also:
- Constant Field Values
-
PAUSED_WAITING_TO_RETRY
public static final int PAUSED_WAITING_TO_RETRY
The download is paused because some network error occurred and the download manager is waiting before retrying the request.- See Also:
- Constant Field Values
-
PAUSED_WAITING_FOR_NETWORK
public static final int PAUSED_WAITING_FOR_NETWORK
The download is waiting for network connectivity to proceed.- See Also:
- Constant Field Values
-
PAUSED_QUEUED_FOR_WIFI
public static final int PAUSED_QUEUED_FOR_WIFI
The download exceeds a size limit for downloads over the mobile network and the download manager is waiting for a Wi-Fi connection to proceed.- See Also:
- Constant Field Values
-
PAUSED_UNKNOWN
public static final int PAUSED_UNKNOWN
The download is paused for some other reason.- See Also:
- Constant Field Values
-
ERROR_UNKNOWN
public static final int ERROR_UNKNOWN
The download has failed with an error that doesn't fit under any other error code.- See Also:
- Constant Field Values
-
ERROR_FILE_ERROR
public static final int ERROR_FILE_ERROR
The download has failed because of storage issue which doesn't fit under any other error code. Use the more specificERROR_INSUFFICIENT_SPACE
andERROR_DEVICE_NOT_FOUND
when appropriate.- See Also:
- Constant Field Values
-
ERROR_UNHANDLED_HTTP_CODE
public static final int ERROR_UNHANDLED_HTTP_CODE
The download has failed because an HTTP code was received that cannot be handled.- See Also:
- Constant Field Values
-
ERROR_HTTP_DATA_ERROR
public static final int ERROR_HTTP_DATA_ERROR
The download has failed because an error occurred while receiving or processing data at the HTTP level.- See Also:
- Constant Field Values
-
ERROR_TOO_MANY_REDIRECTS
public static final int ERROR_TOO_MANY_REDIRECTS
The download has failed because there were too many redirects.- See Also:
- Constant Field Values
-
ERROR_INSUFFICIENT_SPACE
public static final int ERROR_INSUFFICIENT_SPACE
The download has failed because there was insufficient storage space. Typically, this is because the SD card is full.- See Also:
- Constant Field Values
-
ERROR_DEVICE_NOT_FOUND
public static final int ERROR_DEVICE_NOT_FOUND
The download has failed because no external storage device was found. Typically, this is because the SD card is not mounted.- See Also:
- Constant Field Values
-
ERROR_CANNOT_RESUME
public static final int ERROR_CANNOT_RESUME
The download has failed because some possibly transient error occurred but prevents resuming the download.- See Also:
- Constant Field Values
-
ERROR_FILE_ALREADY_EXISTS
public static final int ERROR_FILE_ALREADY_EXISTS
The download has failed because the requested destination file already exists. Please call delete media and the try again.- See Also:
- Constant Field Values
-
CREATOR
public static final android.os.Parcelable.Creator<DownloadStatus> CREATOR
Provides a creator field as required by theParcelable
contract.
-
-
Method Detail
-
createForInvalidDownloadsFile
public static DownloadStatus createForInvalidDownloadsFile()
Creates a newDownloadStatus
instance with error specifying that the DownloadsFile is invalid.- Returns:
- DownloadStatus with code = STATUS_NOT_QUEUED and reason = ERROR_DEVICE_NOT_FOUND.
- See Also:
STATUS_NOT_QUEUED
,ERROR_DEVICE_NOT_FOUND
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isMarkedForDeletion
public boolean isMarkedForDeletion()
Checks if the status indicates the download is currently marked for deletion.- Returns:
- true if the downloads is marked of deletion, otherwise false.
-
getStatusMessage
public int getStatusMessage()
Converts the current status code to a string resource identifier that explains status.- Returns:
- the string resource identifier.
-
toStatusMessage
public static int toStatusMessage(int code)
Converts the given status code to a string resource identifier that explains the status.- Parameters:
code
- the status code.- Returns:
- the matching string resource identifier.
-
getReasonMessage
public int getReasonMessage()
Converts the current status code the string resourced identifier that explains the status.- Returns:
- the string resource identifier.
-
toReasonMessage
public static int toReasonMessage(int reason)
Converts the given reason code to a string resource identifier that explains the reason.- Parameters:
reason
- the reason code.- Returns:
- the matching string resource identifier.
-
getTime
public long getTime()
Gets the date and time when the status changed as number of milliseconds since January 1, 1970, 00:00:00 GMT.- Returns:
- epoch time as milliseconds.
-
getCode
public int getCode()
Gets the status code of the download request.- Returns:
- 0 if the download request is not found, otherwise the download status code.
-
getReason
public int getReason()
Gets the reason code of the download request, if any.- Returns:
- 0 if the download request is not paused or failed, otherwise the reason code.
-
getBytesDownloaded
public long getBytesDownloaded()
Gets the total number of bytes downloaded so far.- Returns:
- 0 if the download request is not found, otherwise the total number of bytes downloaded so far.
-
getActualSize
public long getActualSize()
Gets the actual total size of the file as number of bytes.- Returns:
- 0 if the download request is not found, otherwise the actual total size of the file as number of bytes.
-
getEstimatedSize
public long getEstimatedSize()
Gets the estimated total size of the file as number of bytes.- Returns:
- 0 if the download request is not found, otherwise the estimated total size of the file as number of bytes.
-
getMaxSize
public long getMaxSize()
Gets the maximum size of the file as number of bytes by comparingactualSize
andestimatedSize
- Returns:
- 0 if the download request is not found, otherwise the maximum size of the file as number of bytes.
-
getProgress
public double getProgress()
Calculates the download progress as percentage value.- Returns:
Double.NaN
if theactualSize
is zero, otherwise a value between 0 and 100.
-
describeContents
public int describeContents()
- Specified by:
describeContents
in interfaceandroid.os.Parcelable
-
writeToParcel
public void writeToParcel(android.os.Parcel dest, int flags)
- Specified by:
writeToParcel
in interfaceandroid.os.Parcelable
-
-