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

The following examples show how to use com.google.android.vending.expansion.downloader.Helpers. 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: V14CustomNotification.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
   public Notification updateNotification(Context c) {
       Notification.Builder builder = new Notification.Builder(c);
       builder.setContentTitle(mTitle);
       if (mTotalKB > 0 && -1 != mCurrentKB) {
           builder.setProgress((int) (mTotalKB >> 8), (int) (mCurrentKB >> 8), false);
       } else {
           builder.setProgress(0, 0, true);
       }
       builder.setContentText(Helpers.getDownloadProgressString(mCurrentKB, mTotalKB));
       builder.setContentInfo(c.getString(R.string.time_remaining_notification,
               Helpers.getTimeRemaining(mTimeRemaining)));
       if (mIcon != 0) {
           builder.setSmallIcon(mIcon);
       } else {
           int iconResource = android.R.drawable.stat_sys_download;
           builder.setSmallIcon(iconResource);
       }
       builder.setOngoing(true);
       builder.setTicker(mTicker);
       builder.setContentIntent(mPendingIntent);
       builder.setOnlyAlertOnce(true);

       return builder.getNotification();
   }
 
Example #2
Source File: DownloaderService.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 * 
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example #3
Source File: V14CustomNotification.java    From travelguide with Apache License 2.0 6 votes vote down vote up
@Override
public Notification updateNotification(Context c) {
    Notification.Builder builder = new Notification.Builder(c);
    builder.setContentTitle(mTitle);
    if (mTotalKB > 0 && -1 != mCurrentKB) {
        builder.setProgress((int) (mTotalKB >> 8), (int) (mCurrentKB >> 8), false);
    } else {
        builder.setProgress(0, 0, true);
    }
    builder.setContentText(Helpers.getDownloadProgressString(mCurrentKB, mTotalKB));
    builder.setContentInfo(c.getString(R.string.time_remaining_notification,
            Helpers.getTimeRemaining(mTimeRemaining)));
    if (mIcon != 0) {
        builder.setSmallIcon(mIcon);
    } else {
        int iconResource = android.R.drawable.stat_sys_download;
        builder.setSmallIcon(iconResource);
    }
    builder.setOngoing(true);
    builder.setTicker(mTicker);
    builder.setContentIntent(mPendingIntent);
    builder.setOnlyAlertOnce(true);

    return builder.getNotification();
}
 
Example #4
Source File: DownloaderService.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example #5
Source File: DownloadThread.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example #6
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 #7
Source File: AliteStartManager.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDownloadStateChanged(int newState) {
	setStatus(getString(Helpers.getDownloaderStringResourceIDFromState(newState)));
	if (newState == IDownloaderClient.STATE_COMPLETED) {
		((TextView) findViewById(R.id.downloadProgressPercentTextView)).setText("100%");
		((ProgressBar) findViewById(R.id.downloadProgressBar)).setProgress((int) AliteConfig.EXTENSION_FILE_LENGTH);
		((TextView) findViewById(R.id.downloadTextView)).setText("Download complete.");
		AliteFiles.performMount(this, new IMethodHook() {
			private static final long serialVersionUID = -5369313962579796580L;

			@Override
			public void execute(float deltaTime) {
				startGame();
			}
		}, new ErrorHook());
	}
}
 
Example #8
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example #9
Source File: DownloaderService.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example #10
Source File: DownloaderService.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 *
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example #11
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 * 
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example #12
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 #13
Source File: DownloadThread.java    From QtAndroidTools with MIT License 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example #14
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example #15
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example #16
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * The APK has been updated and a filename has been sent down from the
 * Market call. If the file has the same name as the previous file, we do
 * nothing as the file is guaranteed to be the same. If the file does not
 * have the same name, we download it if it hasn't already been delivered by
 * Market.
 *
 * @param index the index of the file from market (0 = main, 1 = patch)
 * @param filename the name of the new file
 * @param fileSize the size of the new file
 * @return
 */
public boolean handleFileUpdated(DownloadsDB db, int index,
        String filename, long fileSize) {
    DownloadInfo di = db.getDownloadInfoByFileName(filename);
    if (null != di) {
        String oldFile = di.mFileName;
        // cleanup
        if (null != oldFile) {
            if (filename.equals(oldFile)) {
                return false;
            }

            // remove partially downloaded file if it is there
            String deleteFile = Helpers.generateSaveFileName(this, oldFile);
            File f = new File(deleteFile);
            if (f.exists())
                f.delete();
        }
    }
    return !Helpers.doesFileExist(this, filename, fileSize, true);
}
 
Example #17
Source File: DownloadThread.java    From play-apk-expansion with Apache License 2.0 6 votes vote down vote up
/**
 * Called after a successful completion to take any necessary action on the
 * downloaded file.
 */
private void finalizeDestinationFile(State state) throws StopRequest {
    syncDestination(state);
    String tempFilename = state.mFilename;
    String finalFilename = Helpers.generateSaveFileName(mService, mInfo.mFileName);
    if (!state.mFilename.equals(finalFilename)) {
        File startFile = new File(tempFilename);
        File destFile = new File(finalFilename);
        if (mInfo.mTotalBytes != -1 && mInfo.mCurrentBytes == mInfo.mTotalBytes) {
            if (!startFile.renameTo(destFile)) {
                throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                        "unable to finalize destination file");
            }
        } else {
            throw new StopRequest(DownloaderService.STATUS_FILE_DELIVERED_INCORRECTLY,
                    "file delivered with incorrect size. probably due to network not browser configured");
        }
    }
}
 
Example #18
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
Example #19
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 #20
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpURLConnection connection) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    String retryAfterValue = connection.getHeaderField("Retry-After");
    if (retryAfterValue != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + retryAfterValue);
            }
            state.mRetryAfter = Integer.parseInt(retryAfterValue);
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
Example #21
Source File: V3CustomNotification.java    From travelguide with Apache License 2.0 5 votes vote down vote up
@Override
public Notification updateNotification(Context c) {
    Notification n = mNotification;

    n.icon = mIcon;

    n.flags |= Notification.FLAG_ONGOING_EVENT;

    if (android.os.Build.VERSION.SDK_INT > 10) {
        n.flags |= Notification.FLAG_ONLY_ALERT_ONCE; // only matters for
                                                      // Honeycomb
    }

    // Build the RemoteView object
    RemoteViews expandedView = new RemoteViews(
            c.getPackageName(),
            R.layout.status_bar_ongoing_event_progress_bar);

    expandedView.setTextViewText(R.id.title, mTitle);
    // look at strings
    expandedView.setViewVisibility(R.id.description, View.VISIBLE);
    expandedView.setTextViewText(R.id.description,
            Helpers.getDownloadProgressString(mCurrentBytes, mTotalBytes));
    expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE);
    expandedView.setProgressBar(R.id.progress_bar,
            (int) (mTotalBytes >> 8),
            (int) (mCurrentBytes >> 8),
            mTotalBytes <= 0);
    expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE);
    expandedView.setTextViewText(
            R.id.time_remaining,
            c.getString(R.string.time_remaining_notification,
                    Helpers.getTimeRemaining(mTimeRemaining)));
    expandedView.setTextViewText(R.id.progress_text,
            Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
    expandedView.setImageViewResource(R.id.appIcon, mIcon);
    n.contentView = expandedView;
    n.contentIntent = mPendingIntent;
    return n;
}
 
Example #22
Source File: ExpansionActivity.java    From travelguide with Apache License 2.0 5 votes vote down vote up
@Override
public void onDownloadStateChanged(int newState)
{
  mDownloadState.setText(Helpers.getDownloaderStringResourceIDFromState(newState));
  mState = newState;
  switch (mState)
  {
    case IDownloaderClient.STATE_COMPLETED:
      forwardToApp();
      return;
  }

  setUpResumePauseRetry(newState);
}
 
Example #23
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 #24
Source File: AliteStartManager.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
private boolean expansionFilesDelivered() {
       File oldObb = new File(Environment.getExternalStorageDirectory() + "/Android/obb/de.phbouillon.android.games.alite/main.2170.de.phbouillon.android.games.alite.obb");
       if (oldObb.exists()) {
       	oldObb.delete();
       }
    String fileName = Helpers.getExpansionAPKFileName(this, true, AliteConfig.EXTENSION_FILE_VERSION);
    File fileForNewFile = new File(Helpers.generateSaveFileName(this, fileName));
    AliteLog.e("Check for OBB", "OBB exists? " + fileForNewFile.getAbsolutePath());
    return Helpers.doesFileExist(this, fileName, AliteConfig.EXTENSION_FILE_LENGTH, false);
}
 
Example #25
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 * 
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}
 
Example #26
Source File: DownloadThread.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 *
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}
 
Example #27
Source File: DownloadThread.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpResponse response) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    Header header = response.getFirstHeader("Retry-After");
    if (header != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + header.getValue());
            }
            state.mRetryAfter = Integer.parseInt(header.getValue());
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
Example #28
Source File: DownloadThread.java    From QtAndroidTools with MIT License 5 votes vote down vote up
/**
 * Write a data buffer to the destination file.
 *
 * @param data buffer containing the data to write
 * @param bytesRead how many bytes to write from the buffer
 */
private void writeDataToDestination(State state, byte[] data, int bytesRead)
        throws StopRequest {
    for (;;) {
        try {
            if (state.mStream == null) {
                state.mStream = new FileOutputStream(state.mFilename, true);
            }
            state.mStream.write(data, 0, bytesRead);
            // we close after every write --- this may be too inefficient
            closeDestination(state);
            return;
        } catch (IOException ex) {
            if (!Helpers.isExternalMediaMounted()) {
                throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
                        "external media not mounted while writing destination file");
            }

            long availableBytes =
                    Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
            if (availableBytes < bytesRead) {
                throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
                        "insufficient space while writing destination file", ex);
            }
            throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
                    "while writing destination file: " + ex.toString(), ex);
        }
    }
}
 
Example #29
Source File: V3CustomNotification.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Notification updateNotification(Context c) {
    Notification n = mNotification;

    n.icon = mIcon;

    n.flags |= Notification.FLAG_ONGOING_EVENT;

    if (android.os.Build.VERSION.SDK_INT > 10) {
        n.flags |= Notification.FLAG_ONLY_ALERT_ONCE; // only matters for
                                                      // Honeycomb
    }

    // Build the RemoteView object
    RemoteViews expandedView = new RemoteViews(
            c.getPackageName(),
            R.layout.status_bar_ongoing_event_progress_bar);

    expandedView.setTextViewText(R.id.title, mTitle);
    // look at strings
    expandedView.setViewVisibility(R.id.description, View.VISIBLE);
    expandedView.setTextViewText(R.id.description,
            Helpers.getDownloadProgressString(mCurrentBytes, mTotalBytes));
    expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE);
    expandedView.setProgressBar(R.id.progress_bar,
            (int) (mTotalBytes >> 8),
            (int) (mCurrentBytes >> 8),
            mTotalBytes <= 0);
    expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE);
    expandedView.setTextViewText(
            R.id.time_remaining,
            c.getString(R.string.time_remaining_notification,
                    Helpers.getTimeRemaining(mTimeRemaining)));
    expandedView.setTextViewText(R.id.progress_text,
            Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
    expandedView.setImageViewResource(R.id.appIcon, mIcon);
    n.contentView = expandedView;
    n.contentIntent = mPendingIntent;
    return n;
}
 
Example #30
Source File: DownloadThread.java    From QtAndroidTools with MIT License 5 votes vote down vote up
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpURLConnection connection) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    String retryAfterValue = connection.getHeaderField("Retry-After");
    if (retryAfterValue != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + retryAfterValue);
            }
            state.mRetryAfter = Integer.parseInt(retryAfterValue);
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}