Java Code Examples for com.lidroid.xutils.http.HttpHandler

The following examples show how to use com.lidroid.xutils.http.HttpHandler. These examples are extracted from open source projects. 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 Project: android-tv-launcher   Source File: Tools.java    License: MIT License 6 votes vote down vote up
public static void download(String url, String path,
		final IOAuthCallBack iOAuthCallBack) {
	HttpUtils http = new HttpUtils();
	HttpHandler<File> handler = http.download(url, path, false, // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
			false, // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
			new RequestCallBack<File>() {

				@Override
				public void onSuccess(ResponseInfo<File> arg0) {
					if (d)
						Log.d("-----downfile-----", "success");
					iOAuthCallBack.getIOAuthCallBack(arg0.result.getName(),
							0);
				}

                   @Override
                   public void onFailure(com.lidroid.xutils.exception.HttpException e, String s) {
                       if (d)
                           Log.d("-----downfile-----", "fail");
                       iOAuthCallBack.getIOAuthCallBack(e.toString(), 1);
                   }
               });
}
 
Example 2
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
public void addNewDownload(String url, String fileName, String target,
                           boolean autoResume, boolean autoRename,
                           final RequestCallBack<File> callback) throws DbException {
    final DownloadInfo downloadInfo = new DownloadInfo();
    downloadInfo.setDownloadUrl(url);
    downloadInfo.setAutoRename(autoRename);
    downloadInfo.setAutoResume(autoResume);
    downloadInfo.setFileName(fileName);
    downloadInfo.setFileSavePath(target);
    HttpUtils http = new HttpUtils();
    http.configRequestThreadPoolSize(maxDownloadThread);
    HttpHandler<File> handler = http.download(url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
    downloadInfo.setHandler(handler);
    downloadInfo.setState(handler.getState());
    downloadInfoList.add(downloadInfo);
    db.saveBindingId(downloadInfo);
}
 
Example 3
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onLoading(long total, long current, boolean isUploading) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    downloadInfo.setFileLength(total);
    downloadInfo.setProgress(current);
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onLoading(total, current, isUploading);
    }
}
 
Example 4
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
public void addNewDownload(String url, String fileName, String target,
                           boolean autoResume, boolean autoRename,
                           final RequestCallBack<File> callback) throws DbException {
    final DownloadInfo downloadInfo = new DownloadInfo();
    downloadInfo.setDownloadUrl(url);
    downloadInfo.setAutoRename(autoRename);
    downloadInfo.setAutoResume(autoResume);
    downloadInfo.setFileName(fileName);
    downloadInfo.setFileSavePath(target);
    HttpUtils http = new HttpUtils();
    http.configRequestThreadPoolSize(maxDownloadThread);
    HttpHandler<File> handler = http.download(url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
    downloadInfo.setHandler(handler);
    downloadInfo.setState(handler.getState());
    downloadInfoList.add(downloadInfo);
    db.saveBindingId(downloadInfo);
}
 
Example 5
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onLoading(long total, long current, boolean isUploading) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    downloadInfo.setFileLength(total);
    downloadInfo.setProgress(current);
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onLoading(total, current, isUploading);
    }
}
 
Example 6
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
DownloadManager(Context appContext) {
    ColumnConverterFactory.registerColumnConverter(HttpHandler.State.class, new HttpHandlerStateConverter());
    mContext = appContext;
    db = DbUtils.create(mContext);
    try {
        downloadInfoList = db.findAll(Selector.from(DownloadInfo.class));
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (downloadInfoList == null) {
        downloadInfoList = new ArrayList<DownloadInfo>();
    }
}
 
Example 7
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void resumeDownload(DownloadInfo downloadInfo, final RequestCallBack<File> callback) throws DbException {
    HttpUtils http = new HttpUtils();
    http.configRequestThreadPoolSize(maxDownloadThread);
    HttpHandler<File> handler = http.download(
            downloadInfo.getDownloadUrl(),
            downloadInfo.getFileSavePath(),
            downloadInfo.isAutoResume(),
            downloadInfo.isAutoRename(),
            new ManagerCallBack(downloadInfo, callback));
    downloadInfo.setHandler(handler);
    downloadInfo.setState(handler.getState());
    db.saveOrUpdate(downloadInfo);
}
 
Example 8
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void removeDownload(DownloadInfo downloadInfo) throws DbException {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null && !handler.isStopped()) {
        handler.stop();
    }
    downloadInfoList.remove(downloadInfo);
    db.delete(downloadInfo);
}
 
Example 9
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void stopDownload(DownloadInfo downloadInfo) throws DbException {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null && !handler.isStopped()) {
        handler.stop();
    } else {
        downloadInfo.setState(HttpHandler.State.STOPPED);
    }
    db.saveOrUpdate(downloadInfo);
}
 
Example 10
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void stopAllDownload() throws DbException {
    for (DownloadInfo downloadInfo : downloadInfoList) {
        HttpHandler<File> handler = downloadInfo.getHandler();
        if (handler != null && !handler.isStopped()) {
            handler.stop();
        } else {
            downloadInfo.setState(HttpHandler.State.STOPPED);
        }
    }
    db.saveOrUpdateAll(downloadInfoList);
}
 
Example 11
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void backupDownloadInfoList() throws DbException {
    for (DownloadInfo downloadInfo : downloadInfoList) {
        HttpHandler<File> handler = downloadInfo.getHandler();
        if (handler != null) {
            downloadInfo.setState(handler.getState());
        }
    }
    db.saveOrUpdateAll(downloadInfoList);
}
 
Example 12
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onStart();
    }
}
 
Example 13
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onStopped() {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onStopped();
    }
}
 
Example 14
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onSuccess(responseInfo);
    }
}
 
Example 15
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(HttpException error, String msg) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onFailure(error, msg);
    }
}
 
Example 16
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
DownloadManager(Context appContext) {
    ColumnConverterFactory.registerColumnConverter(HttpHandler.State.class, new HttpHandlerStateConverter());
    mContext = appContext;
    db = DbUtils.create(mContext);
    try {
        downloadInfoList = db.findAll(Selector.from(DownloadInfo.class));
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (downloadInfoList == null) {
        downloadInfoList = new ArrayList<DownloadInfo>();
    }
}
 
Example 17
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void resumeDownload(DownloadInfo downloadInfo, final RequestCallBack<File> callback) throws DbException {
    HttpUtils http = new HttpUtils();
    http.configRequestThreadPoolSize(maxDownloadThread);
    HttpHandler<File> handler = http.download(
            downloadInfo.getDownloadUrl(),
            downloadInfo.getFileSavePath(),
            downloadInfo.isAutoResume(),
            downloadInfo.isAutoRename(),
            new ManagerCallBack(downloadInfo, callback));
    downloadInfo.setHandler(handler);
    downloadInfo.setState(handler.getState());
    db.saveOrUpdate(downloadInfo);
}
 
Example 18
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void removeDownload(DownloadInfo downloadInfo) throws DbException {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null && !handler.isStopped()) {
        handler.stop();
    }
    downloadInfoList.remove(downloadInfo);
    db.delete(downloadInfo);
}
 
Example 19
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void stopDownload(DownloadInfo downloadInfo) throws DbException {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null && !handler.isStopped()) {
        handler.stop();
    } else {
        downloadInfo.setState(HttpHandler.State.STOPPED);
    }
    db.saveOrUpdate(downloadInfo);
}
 
Example 20
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void stopAllDownload() throws DbException {
    for (DownloadInfo downloadInfo : downloadInfoList) {
        HttpHandler<File> handler = downloadInfo.getHandler();
        if (handler != null && !handler.isStopped()) {
            handler.stop();
        } else {
            downloadInfo.setState(HttpHandler.State.STOPPED);
        }
    }
    db.saveOrUpdateAll(downloadInfoList);
}
 
Example 21
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
public void backupDownloadInfoList() throws DbException {
    for (DownloadInfo downloadInfo : downloadInfoList) {
        HttpHandler<File> handler = downloadInfo.getHandler();
        if (handler != null) {
            downloadInfo.setState(handler.getState());
        }
    }
    db.saveOrUpdateAll(downloadInfoList);
}
 
Example 22
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onStart();
    }
}
 
Example 23
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onStopped() {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onStopped();
    }
}
 
Example 24
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onSuccess(responseInfo);
    }
}
 
Example 25
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(HttpException error, String msg) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onFailure(error, msg);
    }
}
 
Example 26
Source Project: AndroidAppCodeFramework   Source File: DownloadInfo.java    License: Apache License 2.0 4 votes vote down vote up
public HttpHandler<File> getHandler() {
    return handler;
}
 
Example 27
Source Project: AndroidAppCodeFramework   Source File: DownloadInfo.java    License: Apache License 2.0 4 votes vote down vote up
public void setHandler(HttpHandler<File> handler) {
    this.handler = handler;
}
 
Example 28
Source Project: AndroidAppCodeFramework   Source File: DownloadInfo.java    License: Apache License 2.0 4 votes vote down vote up
public HttpHandler.State getState() {
    return state;
}
 
Example 29
Source Project: AndroidAppCodeFramework   Source File: DownloadInfo.java    License: Apache License 2.0 4 votes vote down vote up
public void setState(HttpHandler.State state) {
    this.state = state;
}
 
Example 30
Source Project: AndroidAppCodeFramework   Source File: DownloadManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public HttpHandler.State getFiledValue(Cursor cursor, int index) {
    return HttpHandler.State.valueOf(cursor.getInt(index));
}