private NotificationCompat.Builder setNotification(final long id) { DownloadInfoRunnable info = getDownload(id); final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); // TODO Intent onClick = new Intent(); onClick.setClassName( getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName()); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Intent.ACTION_VIEW); onClick.putExtra("fromDownloadNotification", true); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity( getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT); int size = DownloadUtils.dpToPixels(getApplicationContext(), 36); Bitmap icon = null; try { // icon = // DownloadUtils.decodeSampledBitmapFromResource(ImageLoader.getInstance().getDiscCache().get(info.getDownload().getIcon()).getAbsolutePath(), size, size); icon = GlideUtils.downloadOnlyFromCache( Aptoide.getContext(), info.getDownload().getIcon(), size, size); } catch (Exception e) { e.printStackTrace(); } mBuilder.setOngoing(true); mBuilder.setContentTitle( getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName())); mBuilder.setContentText(info.getDownload().getName()); if (icon != null) mBuilder.setLargeIcon(icon); mBuilder.setSmallIcon(android.R.drawable.stat_sys_download); mBuilder.setProgress(0, 0, true); mBuilder.setContentIntent(onClickAction); // Log.d("download-trace", "ETA: " + info.getEta()); if (info.getEta() > 0) { String remaining = DownloadUtils.formatEta(info.getEta(), ""); mBuilder.setContentInfo("ETA: " + (!remaining.equals("") ? remaining : "0s")); } return mBuilder; }
private void updateProgress() { Collection<DownloadInfoRunnable> list = getOngoingDownloads(); list.addAll(manager.getmCompletedList()); for (DownloadInfoRunnable info : list) { if (info.getStatusState() instanceof ActiveState) { try { info.getmBuilder() .setProgress(100, info.getPercentDownloaded(), info.getPercentDownloaded() == 0); if (info.getEta() > 0) { String remaining = DownloadUtils.formatEta(info.getEta(), ""); info.getmBuilder().setContentInfo("ETA: " + (!remaining.equals("") ? remaining : "0s")); } mBuilder = info.getmBuilder(); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(-3, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); } return; } } }