/** * init resources */ private void init() { // register DownloadFileChangeListener FileDownloader.registerDownloadFileChangeListener(this); // init DownloadFileInfo if has been downloaded mDownloadFileInfo = FileDownloader.getDownloadFile(mUrl); }
private void initDownloadFileInfos() { this.mDownloadFileInfos = FileDownloader.getDownloadFiles(); mConvertViews.clear(); mSelectedDownloadFileInfos.clear(); if (mOnItemSelectListener != null) { mOnItemSelectListener.onNoneSelect(); } }
@Override protected void onDestroy() { super.onDestroy(); // pause all downloads FileDownloader.pauseAll(); // unregisterDownloadStatusListener FileDownloader.unregisterDownloadStatusListener(mDownloadFileListAdapter); }
@Override public void onDestroy() { super.onDestroy(); FileDownloader.unregisterDownloadStatusListener(mCourseDownloadAdapter); FileDownloader.unregisterDownloadFileChangeListener(this); if (mCourseDownloadAdapter != null) { mCourseDownloadAdapter.release(); } }
public void onClick(DialogInterface dialog, int which) { // file url String url = etUrl.getText().toString().trim(); boolean isDownloadConfigurationTest = false;// TEST if (!isDownloadConfigurationTest) { FileDownloader.start(url); } else { // TEST DownloadConfiguration DownloadConfiguration.Builder builder1 = new DownloadConfiguration.Builder(); builder1.addHeader("Accept", "*/*"); FileDownloader.start(url, builder1.build()); } } });
/** * continue all downloads those recorded by file-downloader * * @param isIncludedErrorDownloads true means force to start download the download file that with error status * @param downloadConfiguration download configuration * @since 0.3.2 */ public static void continueAll(boolean isIncludedErrorDownloads, DownloadConfiguration downloadConfiguration) { List<String> urls = new ArrayList<String>(); List<DownloadFileInfo> downloadFileInfos = getDownloadFiles(); if (downloadFileInfos != null) { for (DownloadFileInfo downloadFileInfo : downloadFileInfos) { if (!DownloadFileUtil.isLegal(downloadFileInfo)) { continue; } if (downloadFileInfo.getStatus() != Status.DOWNLOAD_STATUS_COMPLETED) { if (isIncludedErrorDownloads) { urls.add(downloadFileInfo.getUrl()); } else { if (downloadFileInfo.getStatus() != Status.DOWNLOAD_STATUS_ERROR) { urls.add(downloadFileInfo.getUrl()); } else { // ignore } } } } } start(urls, downloadConfiguration); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = getView(); if (rootView == null) { rootView = inflater.inflate(R.layout.advanced_use__fragment_course_download, null); mRvCourseDownload = (RecyclerView) rootView.findViewById(R.id.rvCourseDownload); // create LinearLayoutManager LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); // vertical layout layoutManager.setOrientation(LinearLayoutManager.VERTICAL); // set layoutManager mRvCourseDownload.setLayoutManager(layoutManager); if (mCourseDownloadAdapter != null) { mCourseDownloadAdapter.release(); } mCourseDownloadAdapter = new CourseDownloadAdapter(getActivity(), null); mRvCourseDownload.setAdapter(mCourseDownloadAdapter); mRvCourseDownload.setItemAnimator(null); mCourseDownloadAdapter.setOnItemSelectListener(this); mLnlyOperation = (LinearLayout) rootView.findViewById(R.id.lnlyOperation); mBtnPause = (Button) rootView.findViewById(R.id.btnPause); mBtnStartOrContinue = (Button) rootView.findViewById(R.id.btnStartOrContinue); mBtnDelete = (Button) rootView.findViewById(R.id.btnDelete); initCourseDownloadData(true); FileDownloader.registerDownloadStatusListener(mCourseDownloadAdapter); FileDownloader.registerDownloadFileChangeListener(this); } return rootView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.custom_model__activity_custom_model); // model data List<CustomVideoInfo> customVideoInfos = getModelData(); // ListView ListView lvDownloadFileList = (ListView) findViewById(R.id.lvDownloadFileList); mCustomDownloadFileListAdapter = new CustomDownloadFileListAdapter(this, customVideoInfos); lvDownloadFileList.setAdapter(mCustomDownloadFileListAdapter); // registerDownloadStatusListener FileDownloader.registerDownloadStatusListener(mCustomDownloadFileListAdapter); }
private void releaseFileDownloader() { FileDownloader.release(); } }
private void initFileDownloader() { // 1.create FileDownloadConfiguration.Builder Builder builder = new FileDownloadConfiguration.Builder(this); // 2.config FileDownloadConfiguration.Builder // config the download path builder.configFileDownloadDir(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "FileDownloader2"); // builder.configFileDownloadDir("/storage/sdcard1/FileDownloader2"); // allow 3 download task at the same time builder.configDownloadTaskSize(3); // config retry download times when failed builder.configRetryDownloadTimes(5); // enable debug mode //builder.configDebugMode(true); // config connect timeout //builder.configConnectTimeout(25000); // 25s // 3.init FileDownloader with the configuration // build FileDownloadConfiguration with the builder FileDownloadConfiguration configuration = builder.build(); FileDownloader.init(configuration); }
@Override protected void onDestroy() { super.onDestroy(); // pause all downloads FileDownloader.pauseAll(); } }
@Override protected void onDestroy() { super.onDestroy(); // // pause all downloads // FileDownloader.pauseAll(); // unregisterDownloadStatusListener FileDownloader.unregisterDownloadStatusListener(mCustomDownloadFileListAdapter); if (mCustomDownloadFileListAdapter != null) { mCustomDownloadFileListAdapter.release(); } } }
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { mSelectedDownloadFileInfos.add(FileDownloader.getDownloadFile(url)); if (mOnItemSelectListener != null) { // select a download file mOnItemSelectListener.onSelected(mSelectedDownloadFileInfos); } } else { mSelectedDownloadFileInfos.remove(FileDownloader.getDownloadFile(url)); if (mSelectedDownloadFileInfos.isEmpty()) { if (mOnItemSelectListener != null) { // select none mOnItemSelectListener.onNoneSelect(); } } else { if (mOnItemSelectListener != null) { // select a download file mOnItemSelectListener.onSelected(mSelectedDownloadFileInfos); } } } } });
@Override public void onClick(View v) { if (selectCoursePreviewInfos != null && !selectCoursePreviewInfos.isEmpty()) { List<String> downloadingUrls = new ArrayList<String>(); for (CoursePreviewInfo info : selectCoursePreviewInfos) { if (info == null || info.getDownloadFileInfo() == null) { continue; } switch (info.getDownloadFileInfo().getStatus()) { case Status.DOWNLOAD_STATUS_WAITING: case Status.DOWNLOAD_STATUS_DOWNLOADING: case Status.DOWNLOAD_STATUS_PREPARING: case Status.DOWNLOAD_STATUS_PREPARED: downloadingUrls.add(info.getDownloadFileInfo().getUrl()); break; } } if (!CollectionUtil.isEmpty(downloadingUrls)) { FileDownloader.pause(downloadingUrls); } else { // do nothing } } } });
@Override public void onClick(View v) { // download course if (TextUtils.isEmpty(coursePreviewInfo.getCourseUrl())) { ToastUtil.showToast(v.getContext(), v.getContext().getString(R.string .advanced_use__course_preview_url_is_empty_note)); return; } ToastUtil.showToast(v.getContext(), v.getContext().getString(R.string .advanced_use__course_preview_add_download) + coursePreviewInfo.getCourseName()); // use FileDownloader to download FileDownloader.start(coursePreviewInfo.getCourseUrl()); } });
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main__activity_main); mLnlyOperation = (LinearLayout) findViewById(R.id.lnlyOperation); mBtnDelete = (Button) findViewById(R.id.btnDelete); mBtnMove = (Button) findViewById(R.id.btnMove); mBtnRename = (Button) findViewById(R.id.btnRename); // ListView ListView lvDownloadFileList = (ListView) findViewById(R.id.lvDownloadFileList); mDownloadFileListAdapter = new DownloadFileListAdapter(this); lvDownloadFileList.setAdapter(mDownloadFileListAdapter); mDownloadFileListAdapter.setOnItemSelectListener(this); // registerDownloadStatusListener boolean isDownloadStatusConfigurationTest = false;// TEST if (!isDownloadStatusConfigurationTest) { // register to listen all FileDownloader.registerDownloadStatusListener(mDownloadFileListAdapter); } else { // register to only listen special url DownloadStatusConfiguration.Builder builder = new DownloadStatusConfiguration.Builder(); builder.addListenUrl("http://182.254.149.157/ftp/image/shop/product/Kids Addition & Subtraction 1.0.apk"); FileDownloader.registerDownloadStatusListener(mDownloadFileListAdapter, builder.build()); } }
private void releaseFileDownloader() { FileDownloader.release(); }