com.google.android.vending.expansion.downloader.DownloadProgressInfo Java Examples

The following examples show how to use com.google.android.vending.expansion.downloader.DownloadProgressInfo. 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: DownloadNotification.java    From QtAndroidTools with MIT License 6 votes vote down vote up
void onDownloadProgress(DownloadProgressInfo progress) {
    mClientProxy.onDownloadProgress(progress);
    if (progress.mOverallTotal <= 0) {
        // we just show the text
        mBuilder.setTicker(mCurrentTitle);
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
        mBuilder.setContentTitle(mCurrentTitle);
        mBuilder.setContentText(mCurrentText);
        mCurrentBuilder = mBuilder;
    } else {
        mActiveDownloadBuilder.setProgress((int) progress.mOverallTotal, (int) progress.mOverallProgress, false);
        mActiveDownloadBuilder.setContentText(Helpers.getDownloadProgressString(progress.mOverallProgress, progress.mOverallTotal));
        mActiveDownloadBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
        mActiveDownloadBuilder.setTicker(mLabel + ": " + mCurrentText);
        mActiveDownloadBuilder.setContentTitle(mLabel);
        mActiveDownloadBuilder.setContentInfo(AndroidApkExpansionFiles.getString(AndroidApkExpansionFiles.STRING_TIME_LEFT) + ": " + Helpers.getTimeRemaining(progress.mTimeRemaining));
        mActiveDownloadBuilder.setOngoing(true);
        mActiveDownloadBuilder.setOnlyAlertOnce(true);
        mCurrentBuilder = mActiveDownloadBuilder;
    }
    mNotificationManager.notify(NOTIFICATION_ID, mCurrentBuilder.build());
}
 
Example #2
Source File: DownloadNotification.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
    mProgressInfo = progress;
    if (null != mClientProxy) {
        mClientProxy.onDownloadProgress(progress);
    }
    if (progress.mOverallTotal <= 0) {
        // we just show the text
        mBuilder.setTicker(mCurrentTitle);
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
        mBuilder.setContentTitle(mCurrentTitle);
        mBuilder.setContentText(mCurrentText);
        mCurrentBuilder = mBuilder;
    } else {
        mActiveDownloadBuilder.setProgress((int) progress.mOverallTotal, (int) progress.mOverallProgress, false);
        mActiveDownloadBuilder.setContentText(Helpers.getDownloadProgressString(progress.mOverallProgress, progress.mOverallTotal));
        mActiveDownloadBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
        mActiveDownloadBuilder.setTicker(mLabel + ": " + mCurrentText);
        mActiveDownloadBuilder.setContentTitle(mLabel);
        mActiveDownloadBuilder.setContentInfo(mContext.getString(R.string.time_remaining_notification,
                Helpers.getTimeRemaining(progress.mTimeRemaining)));
        mCurrentBuilder = mActiveDownloadBuilder;
    }
    mNotificationManager.notify(NOTIFICATION_ID, mCurrentBuilder.build());
}
 
Example #3
Source File: SampleDownloaderActivity.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the state of the various controls based on the progressinfo object
 * sent from the downloader service.
 */
@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
    mAverageSpeed.setText(getString(R.string.kilobytes_per_second,
            Helpers.getSpeedString(progress.mCurrentSpeed)));
    mTimeRemaining.setText(getString(R.string.time_remaining,
            Helpers.getTimeRemaining(progress.mTimeRemaining)));

    progress.mOverallTotal = progress.mOverallTotal;
    mPB.setMax((int) (progress.mOverallTotal >> 8));
    mPB.setProgress((int) (progress.mOverallProgress >> 8));
    mProgressPercent.setText(Long.toString(progress.mOverallProgress
            * 100 /
            progress.mOverallTotal) + "%");
    mProgressFraction.setText(Helpers.getDownloadProgressString
            (progress.mOverallProgress,
                    progress.mOverallTotal));
}
 
Example #4
Source File: DownloadNotification.java    From travelguide with Apache License 2.0 6 votes vote down vote up
@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
    mProgressInfo = progress;
    if (null != mClientProxy) {
        mClientProxy.onDownloadProgress(progress);
    }
    if (progress.mOverallTotal <= 0) {
        // we just show the text
        mNotification.tickerText = mCurrentTitle;
        mNotification.icon = android.R.drawable.stat_sys_download;
        mNotification.setLatestEventInfo(mContext, mLabel, mCurrentText, mContentIntent);
        mCurrentNotification = mNotification;
    } else {
        mCustomNotification.setCurrentBytes(progress.mOverallProgress);
        mCustomNotification.setTotalBytes(progress.mOverallTotal);
        mCustomNotification.setIcon(android.R.drawable.stat_sys_download);
        mCustomNotification.setPendingIntent(mContentIntent);
        mCustomNotification.setTicker(mLabel + ": " + mCurrentText);
        mCustomNotification.setTitle(mLabel);
        mCustomNotification.setTimeRemaining(progress.mTimeRemaining);
        mCurrentNotification = mCustomNotification.updateNotification(mContext);
    }
    mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
}
 
Example #5
Source File: ExpansionActivity.java    From travelguide with Apache License 2.0 6 votes vote down vote up
@Override
public void onDownloadProgress(DownloadProgressInfo progress)
{
  final int currentProgressInPercent =
      (int) (mProgressBar.getMax()*progress.mOverallProgress/(float)progress.mOverallTotal);

  String downloadSpeed = "";
  if (progress.mCurrentSpeed > 0)
    downloadSpeed = Utils.formatDataSize(Math.round(progress.mCurrentSpeed*1024))+ "/s";

  final String progressStr = Utils.formatDataSize(progress.mOverallProgress) + "/"
                             + Utils.formatDataSize(progress.mOverallTotal);

  mSpeed.setText(downloadSpeed);
  mTotal.setText(progressStr);
  mProgressBar.setProgress(currentProgressInPercent);
}
 
Example #6
Source File: DownloadNotification.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
   public void onDownloadProgress(DownloadProgressInfo progress) {
       mProgressInfo = progress;
       if (null != mClientProxy) {
           mClientProxy.onDownloadProgress(progress);
       }
       if (progress.mOverallTotal <= 0) {
           // we just show the text
           mNotification.tickerText = mCurrentTitle;
           mNotification.icon = android.R.drawable.stat_sys_download;
           mNotification.setLatestEventInfo(mContext, mLabel, mCurrentText, mContentIntent);
           mCurrentNotification = mNotification;
       } else {
           mCustomNotification.setCurrentBytes(progress.mOverallProgress);
           mCustomNotification.setTotalBytes(progress.mOverallTotal);
           mCustomNotification.setIcon(android.R.drawable.stat_sys_download);
           mCustomNotification.setPendingIntent(mContentIntent);
           mCustomNotification.setTicker(mLabel + ": " + mCurrentText);
           mCustomNotification.setTitle(mLabel);
           mCustomNotification.setTimeRemaining(progress.mTimeRemaining);
           mCurrentNotification = mCustomNotification.updateNotification(mContext);
       }
       mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
   }
 
Example #7
Source File: BroadcastDownloaderClient.java    From QtAndroidTools with MIT License 5 votes vote down vote up
@Override public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case ACTION_STATE_CHANGED:
            int state = intent.getIntExtra(EXTRA_NEW_STATE, -1);
            onDownloadStateChanged(state);
            break;
        case ACTION_PROGRESS:
            DownloadProgressInfo info = intent.getParcelableExtra(EXTRA_PROGRESS);
            onDownloadProgress(info);
            break;
    }
}
 
Example #8
Source File: DownloaderService.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
public void notifyUpdateBytes(long totalBytesSoFar) {
    long timeRemaining;
    long currentTime = SystemClock.uptimeMillis();
    if (0 != mMillisecondsAtSample) {
        // we have a sample.
        long timePassed = currentTime - mMillisecondsAtSample;
        long bytesInSample = totalBytesSoFar - mBytesAtSample;
        float currentSpeedSample = (float) bytesInSample / (float) timePassed;
        if (0 != mAverageDownloadSpeed) {
            mAverageDownloadSpeed = SMOOTHING_FACTOR * currentSpeedSample
                    + (1 - SMOOTHING_FACTOR) * mAverageDownloadSpeed;
        } else {
            mAverageDownloadSpeed = currentSpeedSample;
        }
        timeRemaining = (long) ((mTotalLength - totalBytesSoFar) / mAverageDownloadSpeed);
    } else {
        timeRemaining = -1;
    }
    mMillisecondsAtSample = currentTime;
    mBytesAtSample = totalBytesSoFar;
    mNotification.onDownloadProgress(
            new DownloadProgressInfo(mTotalLength,
                    totalBytesSoFar,
                    timeRemaining,
                    mAverageDownloadSpeed)
            );

}
 
Example #9
Source File: DownloaderService.java    From travelguide with Apache License 2.0 5 votes vote down vote up
public void notifyUpdateBytes(long totalBytesSoFar) {
    long timeRemaining;
    long currentTime = SystemClock.uptimeMillis();
    if (0 != mMillisecondsAtSample) {
        // we have a sample.
        long timePassed = currentTime - mMillisecondsAtSample;
        long bytesInSample = totalBytesSoFar - mBytesAtSample;
        float currentSpeedSample = (float) bytesInSample / (float) timePassed;
        if (0 != mAverageDownloadSpeed) {
            mAverageDownloadSpeed = SMOOTHING_FACTOR * currentSpeedSample
                    + (1 - SMOOTHING_FACTOR) * mAverageDownloadSpeed;
        } else {
            mAverageDownloadSpeed = currentSpeedSample;
        }
        timeRemaining = (long) ((mTotalLength - totalBytesSoFar) / mAverageDownloadSpeed);
    } else {
        timeRemaining = -1;
    }
    mMillisecondsAtSample = currentTime;
    mBytesAtSample = totalBytesSoFar;
    mNotification.onDownloadProgress(
            new DownloadProgressInfo(mTotalLength,
                    totalBytesSoFar,
                    timeRemaining,
                    mAverageDownloadSpeed)
            );

}
 
Example #10
Source File: AliteStartManager.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
	progressUpdateCalls++;
	avgSpeed += progress.mCurrentSpeed;
	TextView report = (TextView) findViewById(R.id.downloadTextView);
	int mbRead = (int) (progress.mOverallProgress / 1024.0f / 1024.0f);
	int mbTotal = (int) (progress.mOverallTotal / 1024.0f / 1024.0f);
	report.setText("Downloading... " + mbRead + " of " + mbTotal + "MB read. Speed: " + String.format(Locale.getDefault(), "%4.2f", (avgSpeed / (float) progressUpdateCalls / 1024.0f)) + " MB/s. Time remaining: " + (int) ((float) progress.mTimeRemaining / 1000.0f) + "s.");
	((ProgressBar) findViewById(R.id.downloadProgressBar)).setMax((int) progress.mOverallTotal);
	((ProgressBar) findViewById(R.id.downloadProgressBar)).setProgress((int) progress.mOverallProgress);
	((TextView) findViewById(R.id.downloadProgressPercentTextView)).setText((int) (((float) progress.mOverallProgress / (float) progress.mOverallTotal * 100.0f)) + "%"); 
	AliteLog.d("Progress", "Current Speed: " + progress.mCurrentSpeed + ", Overall progress: " + progress.mOverallProgress + ", Total progress: " + progress.mOverallTotal + ", Time Remaining: " + progress.mTimeRemaining);
}
 
Example #11
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
public void notifyUpdateBytes(long totalBytesSoFar) {
    long timeRemaining;
    long currentTime = SystemClock.uptimeMillis();
    if (0 != mMillisecondsAtSample) {
        // we have a sample.
        long timePassed = currentTime - mMillisecondsAtSample;
        long bytesInSample = totalBytesSoFar - mBytesAtSample;
        float currentSpeedSample = (float) bytesInSample / (float) timePassed;
        if (0 != mAverageDownloadSpeed) {
            mAverageDownloadSpeed = SMOOTHING_FACTOR * currentSpeedSample
                    + (1 - SMOOTHING_FACTOR) * mAverageDownloadSpeed;
        } else {
            mAverageDownloadSpeed = currentSpeedSample;
        }
        timeRemaining = (long) ((mTotalLength - totalBytesSoFar) / mAverageDownloadSpeed);
    } else {
        timeRemaining = -1;
    }
    mMillisecondsAtSample = currentTime;
    mBytesAtSample = totalBytesSoFar;
    mNotification.onDownloadProgress(
            new DownloadProgressInfo(mTotalLength,
                    totalBytesSoFar,
                    timeRemaining,
                    mAverageDownloadSpeed)
            );

}
 
Example #12
Source File: DownloadNotification.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
    mProgressInfo = progress;
    if (null != mClientProxy) {
        mClientProxy.onDownloadProgress(progress);
    }
    if (progress.mOverallTotal <= 0) {
        // we just show the text
        mBuilder.setTicker(mCurrentTitle)
        .setSmallIcon(android.R.drawable.stat_sys_download)
        .setContentTitle(mCurrentTitle)
        .setContentText(mCurrentText);
        mCurrentBuilder = mBuilder;
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            mActiveDownloadBuilder.setProgress((int) progress.mOverallTotal, (int) progress.mOverallProgress, false);
        }
        mActiveDownloadBuilder.setContentText(Helpers.getDownloadProgressString(progress.mOverallProgress, progress.mOverallTotal))
        .setSmallIcon(android.R.drawable.stat_sys_download)
        .setTicker(mLabel + ": " + mCurrentText)
        .setContentTitle(mLabel)
        .setContentInfo(mContext.getString(Helpers.getStringResource(mContext, "time_remaining_notification"),
                Helpers.getTimeRemaining(progress.mTimeRemaining)));
        mCurrentBuilder = mActiveDownloadBuilder;
    }
    Notification notification;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notification = mCurrentBuilder.build();
    } else {
        notification = mCurrentBuilder.getNotification();
    }
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}
 
Example #13
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
public void notifyUpdateBytes(long totalBytesSoFar) {
    long timeRemaining;
    long currentTime = SystemClock.uptimeMillis();
    if (0 != mMillisecondsAtSample) {
        // we have a sample.
        long timePassed = currentTime - mMillisecondsAtSample;
        long bytesInSample = totalBytesSoFar - mBytesAtSample;
        float currentSpeedSample = (float) bytesInSample / (float) timePassed;
        if (0 != mAverageDownloadSpeed) {
            mAverageDownloadSpeed = SMOOTHING_FACTOR * currentSpeedSample
                    + (1 - SMOOTHING_FACTOR) * mAverageDownloadSpeed;
        } else {
            mAverageDownloadSpeed = currentSpeedSample;
        }
        timeRemaining = (long) ((mTotalLength - totalBytesSoFar) / mAverageDownloadSpeed);
    } else {
        timeRemaining = -1;
    }
    mMillisecondsAtSample = currentTime;
    mBytesAtSample = totalBytesSoFar;
    mNotification.onDownloadProgress(
            new DownloadProgressInfo(mTotalLength,
                    totalBytesSoFar,
                    timeRemaining,
                    mAverageDownloadSpeed)
            );

}
 
Example #14
Source File: ClientProxy.java    From QtAndroidTools with MIT License 4 votes vote down vote up
@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
    Bundle params = new Bundle(1);
    params.putParcelable(BroadcastDownloaderClient.EXTRA_PROGRESS, progress);
    send(BroadcastDownloaderClient.ACTION_PROGRESS, params);
}