Java Code Examples for com.liulishuo.filedownloader.model.FileDownloadStatus#paused()
The following examples show how to use
com.liulishuo.filedownloader.model.FileDownloadStatus#paused() .
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: CacheDownloadingAdapter.java From YCAudioPlayer with Apache License 2.0 | 6 votes |
@Override public void updateNotDownloaded(int status, long sofar, long total) { AppLogUtils.e("ViewHolder----"+"updateNotDownloaded--------"+status+"---"+sofar+"---"+total); if (sofar > 0 && total > 0) { final float percent = sofar / (float) total; pb.setProgress((int) (percent * 100)); } else { pb.setProgress(0); } switch (status) { case FileDownloadStatus.error: ivDownload.setBackgroundResource(R.drawable.ic_note_btn_play_white); ivDownload.setTag(R.drawable.ic_note_btn_play_white); tvState.setText("错误"); break; case FileDownloadStatus.paused: ivDownload.setBackgroundResource(R.drawable.ic_note_btn_play_white); ivDownload.setTag(R.drawable.ic_note_btn_play_white); tvState.setText("暂停"); break; default: ivDownload.setBackgroundResource(R.drawable.ic_note_btn_play_white); ivDownload.setTag(R.drawable.ic_note_btn_play_white); break; } }
Example 2
Source File: DialogListAdapter.java From YCAudioPlayer with Apache License 2.0 | 6 votes |
@Override public void updateNotDownloaded(int status, long sofar, long total) { AppLogUtils.e("ViewHolder----"+"updateNotDownloaded--------"+status+"---"+sofar+"---"+total); if (sofar > 0 && total > 0) { final float percent = sofar / (float) total; circlePb.setProgress((int) (percent * 100)); } else { circlePb.setProgress(0); } switch (status) { case FileDownloadStatus.error: ivDownload.setBackgroundResource(R.drawable.icon_cache_download); tvState.setText("错误"); break; case FileDownloadStatus.paused: ivDownload.setBackgroundResource(R.drawable.icon_cache_download); tvState.setText("暂停"); break; default: ivDownload.setBackgroundResource(R.drawable.icon_cache_download); break; } tvState.setTag(STATE_START); }
Example 3
Source File: TasksManagerDemoActivity.java From FileDownloader with Apache License 2.0 | 6 votes |
public void updateNotDownloaded(final int status, final long sofar, final long total) { if (sofar > 0 && total > 0) { final float percent = sofar / (float) total; taskPb.setMax(100); taskPb.setProgress((int) (percent * 100)); } else { taskPb.setMax(1); taskPb.setProgress(0); } switch (status) { case FileDownloadStatus.error: taskStatusTv.setText(R.string.tasks_manager_demo_status_error); break; case FileDownloadStatus.paused: taskStatusTv.setText(R.string.tasks_manager_demo_status_paused); break; default: taskStatusTv.setText(R.string.tasks_manager_demo_status_not_downloaded); break; } taskActionBtn.setText(R.string.start); }
Example 4
Source File: DownloadStatusCallback.java From FileDownloader with Apache License 2.0 | 6 votes |
private void onStatusChanged(final byte status) { // In current situation, it maybe invoke this method simultaneously between #onPause() and // others. if (status == FileDownloadStatus.paused) { if (FileDownloadLog.NEED_LOG) { /** * Already paused or the current status is paused. * * We don't need to call-back to Task in here, because the pause status has * already handled by {@link BaseDownloadTask#pause()} manually. * * In some case, it will arrive here by High concurrent cause. For performance * more make sense. * * High concurrent cause. */ FileDownloadLog.d(this, "High concurrent cause, Already paused and we don't " + "need to call-back to Task in here, %d", model.getId()); } return; } MessageSnapshotFlow.getImpl().inflow( MessageSnapshotTaker.take(status, model, processParams)); }
Example 5
Source File: FileDownloadUtils.java From okdownload with Apache License 2.0 | 5 votes |
public static byte convertDownloadStatus(final StatusUtil.Status status) { switch (status) { case COMPLETED: return FileDownloadStatus.completed; case IDLE: return FileDownloadStatus.paused; case PENDING: return FileDownloadStatus.pending; case RUNNING: return FileDownloadStatus.progress; default: return FileDownloadStatus.INVALID_STATUS; } }
Example 6
Source File: DownloadHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
private int getDownloadResult(DownloadMissionEntity entity) { switch (FileDownloader.getImpl().getStatus((int) entity.missionId, entity.getFilePath())) { case FileDownloadStatus.completed: return RESULT_SUCCEED; case FileDownloadStatus.error: case FileDownloadStatus.warn: case FileDownloadStatus.paused: return RESULT_FAILED; default: return RESULT_DOWNLOADING; } }
Example 7
Source File: DownloadTaskHunter.java From FileDownloader with Apache License 2.0 | 5 votes |
@Override public boolean updateKeepFlow(MessageSnapshot snapshot) { final int currentStatus = getStatus(); final int nextStatus = snapshot.getStatus(); if (FileDownloadStatus.paused == currentStatus && FileDownloadStatus.isIng(nextStatus)) { if (FileDownloadLog.NEED_LOG) { /** * Occur such situation, must be the running-mStatus waiting for turning up in flow * thread pool(or binder thread) when there is someone invoked the {@link #pause()}. * * High concurrent cause. */ FileDownloadLog.d(this, "High concurrent cause, callback pending, but has already" + " be paused %d", getId()); } return true; } if (!FileDownloadStatus.isKeepFlow(currentStatus, nextStatus)) { if (FileDownloadLog.NEED_LOG) { FileDownloadLog.d(this, "can't update mStatus change by keep flow, %d, but the" + " current mStatus is %d, %d", mStatus, getStatus(), getId()); } return false; } update(snapshot); return true; }
Example 8
Source File: DownloadVideoAdapter.java From v9porn with MIT License | 4 votes |
@Override protected void convert(BaseViewHolder helper, V9PornItem item) { helper.setText(R.id.tv_91porn_item_title, item.getTitleWithDuration()); ImageView simpleDraweeView = helper.getView(R.id.iv_91porn_item_img); Uri uri = Uri.parse(item.getImgUrl()); GlideApp.with(helper.itemView).load(uri).placeholder(R.drawable.placeholder).transition(new DrawableTransitionOptions().crossFade(300)).into(simpleDraweeView); helper.setProgress(R.id.progressBar_download, item.getProgress()); helper.setText(R.id.tv_download_progress, String.valueOf(item.getProgress()) + "%"); helper.setText(R.id.tv_download_filesize, Formatter.formatFileSize(helper.itemView.getContext(), item.getSoFarBytes()).replace("MB", "") + "/ " + Formatter.formatFileSize(helper.itemView.getContext(), item.getTotalFarBytes())); if (item.getStatus() == FileDownloadStatus.completed) { helper.setText(R.id.tv_download_speed, "已完成"); helper.setVisible(R.id.iv_download_control, false); } else { //未下载完成,显示控制 helper.setVisible(R.id.iv_download_control, true); if (FileDownloader.getImpl().isServiceConnected()) { helper.setImageResource(R.id.iv_download_control, R.drawable.pause_download); if (item.getStatus() == FileDownloadStatus.progress) { helper.setText(R.id.tv_download_speed, item.getSpeed() + " KB/s"); } else if (item.getStatus() == FileDownloadStatus.paused) { helper.setText(R.id.tv_download_speed, "暂停中"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } else if (item.getStatus() == FileDownloadStatus.pending) { helper.setText(R.id.tv_download_speed, "准备中"); } else if (item.getStatus() == FileDownloadStatus.started) { helper.setText(R.id.tv_download_speed, "开始下载"); } else if (item.getStatus() == FileDownloadStatus.connected) { helper.setText(R.id.tv_download_speed, "连接中"); } else if (item.getStatus() == FileDownloadStatus.error) { helper.setText(R.id.tv_download_speed, "下载错误"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } else if (item.getStatus() == FileDownloadStatus.retry) { helper.setText(R.id.tv_download_speed, "重试中"); } else if (item.getStatus() == FileDownloadStatus.warn) { helper.setText(R.id.tv_download_speed, "警告"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } } else { helper.setText(R.id.tv_download_speed, "暂停中"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } } helper.addOnClickListener(R.id.iv_download_control); helper.addOnClickListener(R.id.right_menu_delete); }
Example 9
Source File: DownloadVideoAdapter.java From v9porn with MIT License | 4 votes |
@Override protected void convert(BaseViewHolder helper, V9PornItem item) { helper.setText(R.id.tv_91porn_item_title, item.getTitleWithDuration()); ImageView simpleDraweeView = helper.getView(R.id.iv_91porn_item_img); Uri uri = Uri.parse(item.getImgUrl()); GlideApp.with(helper.itemView).load(uri).placeholder(R.drawable.placeholder).transition(new DrawableTransitionOptions().crossFade(300)).into(simpleDraweeView); helper.setProgress(R.id.progressBar_download, item.getProgress()); helper.setText(R.id.tv_download_progress, String.valueOf(item.getProgress()) + "%"); helper.setText(R.id.tv_download_filesize, Formatter.formatFileSize(helper.itemView.getContext(), item.getSoFarBytes()).replace("MB", "") + "/ " + Formatter.formatFileSize(helper.itemView.getContext(), item.getTotalFarBytes())); if (item.getStatus() == FileDownloadStatus.completed) { helper.setText(R.id.tv_download_speed, "已完成"); helper.setVisible(R.id.iv_download_control, false); } else { //未下载完成,显示控制 helper.setVisible(R.id.iv_download_control, true); if (FileDownloader.getImpl().isServiceConnected()) { helper.setImageResource(R.id.iv_download_control, R.drawable.pause_download); if (item.getStatus() == FileDownloadStatus.progress) { helper.setText(R.id.tv_download_speed, item.getSpeed() + " KB/s"); } else if (item.getStatus() == FileDownloadStatus.paused) { helper.setText(R.id.tv_download_speed, "暂停中"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } else if (item.getStatus() == FileDownloadStatus.pending) { helper.setText(R.id.tv_download_speed, "准备中"); } else if (item.getStatus() == FileDownloadStatus.started) { helper.setText(R.id.tv_download_speed, "开始下载"); } else if (item.getStatus() == FileDownloadStatus.connected) { helper.setText(R.id.tv_download_speed, "连接中"); } else if (item.getStatus() == FileDownloadStatus.error) { helper.setText(R.id.tv_download_speed, "下载错误"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } else if (item.getStatus() == FileDownloadStatus.retry) { helper.setText(R.id.tv_download_speed, "重试中"); } else if (item.getStatus() == FileDownloadStatus.warn) { helper.setText(R.id.tv_download_speed, "警告"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } } else { helper.setText(R.id.tv_download_speed, "暂停中"); helper.setImageResource(R.id.iv_download_control, R.drawable.start_download); } } helper.addOnClickListener(R.id.iv_download_control); helper.addOnClickListener(R.id.right_menu_delete); }
Example 10
Source File: NotificationSampleActivity.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public void show(boolean statusChanged, int status, boolean isShowProgress) { String desc = ""; switch (status) { case FileDownloadStatus.pending: desc += " pending"; builder.setProgress(getTotal(), getSofar(), true); break; case FileDownloadStatus.started: desc += " started"; builder.setProgress(getTotal(), getSofar(), true); break; case FileDownloadStatus.progress: desc += " progress"; builder.setProgress(getTotal(), getSofar(), getTotal() <= 0); break; case FileDownloadStatus.retry: desc += " retry"; builder.setProgress(getTotal(), getSofar(), true); break; case FileDownloadStatus.error: desc += " error"; builder.setProgress(getTotal(), getSofar(), false); break; case FileDownloadStatus.paused: desc += " paused"; builder.setProgress(getTotal(), getSofar(), false); break; case FileDownloadStatus.completed: desc += " completed"; builder.setProgress(getTotal(), getSofar(), false); break; case FileDownloadStatus.warn: desc += " warn"; builder.setProgress(0, 0, true); break; } builder.setContentTitle(getTitle()).setContentText(desc); getManager().notify(getId(), builder.build()); }
Example 11
Source File: SmallMessageSnapshot.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public byte getStatus() { return FileDownloadStatus.paused; }
Example 12
Source File: LargeMessageSnapshot.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public byte getStatus() { return FileDownloadStatus.paused; }
Example 13
Source File: FileDownloadList.java From FileDownloader with Apache License 2.0 | 4 votes |
/** * @param willRemoveDownload will be remove */ public boolean remove(final BaseDownloadTask.IRunningTask willRemoveDownload, MessageSnapshot snapshot) { final byte removeByStatus = snapshot.getStatus(); boolean succeed; synchronized (mList) { succeed = mList.remove(willRemoveDownload); if (succeed && mList.size() == 0) { if (FileDownloadServiceProxy.getImpl().isRunServiceForeground()) { FileDownloader.getImpl().stopForeground(true); } } } if (FileDownloadLog.NEED_LOG) { if (mList.size() == 0) { FileDownloadLog.v(this, "remove %s left %d %d", willRemoveDownload, removeByStatus, mList.size()); } } if (succeed) { final IFileDownloadMessenger messenger = willRemoveDownload.getMessageHandler(). getMessenger(); // Notify 2 Listener switch (removeByStatus) { case FileDownloadStatus.warn: messenger.notifyWarn(snapshot); break; case FileDownloadStatus.error: messenger.notifyError(snapshot); break; case FileDownloadStatus.paused: messenger.notifyPaused(snapshot); break; case FileDownloadStatus.completed: messenger .notifyBlockComplete(MessageSnapshotTaker.takeBlockCompleted(snapshot)); break; default: // ignored } } else { FileDownloadLog.e(this, "remove error, not exist: %s %d", willRemoveDownload, removeByStatus); } return succeed; }
Example 14
Source File: DownloadTaskHunter.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public boolean pause() { if (FileDownloadStatus.isOver(getStatus())) { if (FileDownloadLog.NEED_LOG) { /** * The over-mStatus call-backed and set the over-mStatus to this task between here * area and remove from the {@link FileDownloadList}. * * High concurrent cause. */ FileDownloadLog.d(this, "High concurrent cause, Already is over, can't pause " + "again, %d %d", getStatus(), mTask.getRunningTask().getOrigin().getId()); } return false; } this.mStatus = FileDownloadStatus.paused; final BaseDownloadTask.IRunningTask runningTask = mTask.getRunningTask(); final BaseDownloadTask origin = runningTask.getOrigin(); FileDownloadTaskLauncher.getImpl().expire(this); if (FileDownloadLog.NEED_LOG) { FileDownloadLog.v(this, "the task[%d] has been expired from the launch pool.", getId()); } if (!FileDownloader.getImpl().isServiceConnected()) { if (FileDownloadLog.NEED_LOG) { FileDownloadLog.d(this, "request pause the task[%d] to the download service," + " but the download service isn't connected yet.", origin.getId()); } } else { FileDownloadServiceProxy.getImpl().pause(origin.getId()); } // For make sure already added event mListener for receive paused event FileDownloadList.getImpl().add(runningTask); FileDownloadList.getImpl().remove(runningTask, MessageSnapshotTaker.catchPause(origin)); FileDownloader.getImpl().getLostConnectedHandler().taskWorkFine(runningTask); return true; }
Example 15
Source File: DownloadTaskHunter.java From FileDownloader with Apache License 2.0 | 4 votes |
@SuppressWarnings("checkstyle:emptyblock") @Override public void start() { if (mStatus != FileDownloadStatus.toLaunchPool) { FileDownloadLog.w(this, "High concurrent cause, this task %d will not start," + " because the of status isn't toLaunchPool: %d", getId(), mStatus); return; } final BaseDownloadTask.IRunningTask runningTask = mTask.getRunningTask(); final BaseDownloadTask origin = runningTask.getOrigin(); final ILostServiceConnectedHandler lostConnectedHandler = FileDownloader.getImpl(). getLostConnectedHandler(); try { if (lostConnectedHandler.dispatchTaskStart(runningTask)) { return; } synchronized (mPauseLock) { if (mStatus != FileDownloadStatus.toLaunchPool) { FileDownloadLog.w(this, "High concurrent cause, this task %d will not start," + " the status can't assign to toFileDownloadService, because " + "the status isn't toLaunchPool: %d", getId(), mStatus); return; } mStatus = FileDownloadStatus.toFileDownloadService; } FileDownloadList.getImpl().add(runningTask); if (FileDownloadHelper.inspectAndInflowDownloaded( origin.getId(), origin.getTargetFilePath(), origin.isForceReDownload(), true) ) { // Will be removed when the complete message is received in #update return; } final boolean succeed = FileDownloadServiceProxy.getImpl(). start( origin.getUrl(), origin.getPath(), origin.isPathAsDirectory(), origin.getCallbackProgressTimes(), origin.getCallbackProgressMinInterval(), origin.getAutoRetryTimes(), origin.isForceReDownload(), mTask.getHeader(), origin.isWifiRequired()); if (mStatus == FileDownloadStatus.paused) { FileDownloadLog.w(this, "High concurrent cause, this task %d will be paused," + "because of the status is paused, so the pause action must be " + "applied", getId()); if (succeed) { FileDownloadServiceProxy.getImpl().pause(getId()); } return; } if (!succeed) { //noinspection StatementWithEmptyBody if (!lostConnectedHandler.dispatchTaskStart(runningTask)) { final MessageSnapshot snapshot = prepareErrorMessage( new RuntimeException("Occur Unknown Error, when request to start" + " maybe some problem in binder, maybe the process was killed " + "in unexpected.")); if (FileDownloadList.getImpl().isNotContains(runningTask)) { lostConnectedHandler.taskWorkFine(runningTask); FileDownloadList.getImpl().add(runningTask); } FileDownloadList.getImpl().remove(runningTask, snapshot); } else { // the FileDownload Service host process was killed when request stating and it // will be restarted by LostServiceConnectedHandler. } } else { lostConnectedHandler.taskWorkFine(runningTask); } } catch (Throwable e) { e.printStackTrace(); FileDownloadList.getImpl().remove(runningTask, prepareErrorMessage(e)); } }