com.lidroid.xutils.http.HttpHandler Java Examples

The following examples show how to use com.lidroid.xutils.http.HttpHandler. 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: DownloadManager.java    From AndroidAppCodeFramework with 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 #2
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: Tools.java    From android-tv-launcher with 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 #4
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #5
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 #7
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #8
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #9
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #10
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 #17
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #18
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #19
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #20
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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 #22
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #23
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #24
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 #25
Source File: DownloadManager.java    From AndroidAppCodeFramework with 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 File: DownloadManager.java    From AndroidAppCodeFramework with 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));
}
 
Example #27
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 4 votes vote down vote up
@Override
public HttpHandler.State getFiledValue(String fieldStringValue) {
    if (fieldStringValue == null) return null;
    return HttpHandler.State.valueOf(fieldStringValue);
}
 
Example #28
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 4 votes vote down vote up
@Override
public Object fieldValue2ColumnValue(HttpHandler.State fieldValue) {
    return fieldValue.value();
}
 
Example #29
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 4 votes vote down vote up
@Override
public Object fieldValue2ColumnValue(HttpHandler.State fieldValue) {
    return fieldValue.value();
}
 
Example #30
Source File: DownloadInfo.java    From AndroidAppCodeFramework with Apache License 2.0 4 votes vote down vote up
public void setState(HttpHandler.State state) {
    this.state = state;
}