当前位置: 首页>>代码示例>>Java>>正文


Java Callback.CancelledException方法代码示例

本文整理汇总了Java中org.xutils.common.Callback.CancelledException方法的典型用法代码示例。如果您正苦于以下问题:Java Callback.CancelledException方法的具体用法?Java Callback.CancelledException怎么用?Java Callback.CancelledException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xutils.common.Callback的用法示例。


在下文中一共展示了Callback.CancelledException方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeTo

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
public void writeTo(OutputStream out) throws IOException {

    if (callBackHandler != null && !callBackHandler.updateProgress(total, current, true)) {
        throw new Callback.CancelledException("upload stopped!");
    }

    for (KeyValue kv : multipartParams) {
        String name = kv.key;
        Object value = kv.value;
        if (!TextUtils.isEmpty(name) && value != null) {
            writeEntry(out, name, value);
        }
    }
    writeLine(out, TWO_DASHES_BYTES, BOUNDARY_PREFIX_BYTES, boundaryPostfixBytes, TWO_DASHES_BYTES);
    out.flush();

    if (callBackHandler != null) {
        callBackHandler.updateProgress(total, total, true);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:MultipartBody.java

示例2: writeStreamAndCloseIn

import org.xutils.common.Callback; //导入方法依赖的package包/类
private void writeStreamAndCloseIn(OutputStream out, InputStream in) throws IOException {
    if (out instanceof CounterOutputStream) {
        ((CounterOutputStream) out).addStream(in);
    } else {
        try {
            int len;
            byte[] buf = new byte[1024];
            while ((len = in.read(buf)) >= 0) {
                out.write(buf, 0, len);
                current += len;
                if (callBackHandler != null && !callBackHandler.updateProgress(total, current, false)) {
                    throw new Callback.CancelledException("upload stopped!");
                }
            }
        } finally {
            IOUtil.closeQuietly(in);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:MultipartBody.java

示例3: writeTo

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
public void writeTo(OutputStream out) throws IOException {
    if (callBackHandler != null && !callBackHandler.updateProgress(total, current, true)) {
        throw new Callback.CancelledException("upload stopped!");
    }

    byte[] buffer = new byte[1024];
    try {
        int len = 0;
        while ((len = content.read(buffer)) != -1) {
            out.write(buffer, 0, len);
            current += len;
            if (callBackHandler != null && !callBackHandler.updateProgress(total, current, false)) {
                throw new Callback.CancelledException("upload stopped!");
            }
        }
        out.flush();

        if (callBackHandler != null) {
            callBackHandler.updateProgress(total, total, true);
        }
    } finally {
        IOUtil.closeQuietly(content);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:InputStreamBody.java

示例4: startSync

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
public <T> T startSync(AbsTask<T> task) throws Throwable {
    T result = null;
    try {
        task.onWaiting();
        task.onStarted();
        result = task.doBackground();
        task.onSuccess(result);
    } catch (Callback.CancelledException cex) {
        task.onCancelled(cex);
    } catch (Throwable ex) {
        task.onError(ex, false);
        throw ex;
    } finally {
        task.onFinished();
    }
    return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:TaskControllerImpl.java

示例5: onCancelled

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
protected void onCancelled(Callback.CancelledException cex) {
    if (tracker != null) {
        tracker.onCancelled(request);
    }
    callback.onCancelled(cex);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:HttpTask.java

示例6: onCancelled

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
public void onCancelled(Callback.CancelledException cex) {
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:DefaultDownloadViewHolder.java

示例7: onCancelled

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
public void onCancelled(Callback.CancelledException cex) {
    refresh();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:DownloadActivity.java

示例8: writeEntry

import org.xutils.common.Callback; //导入方法依赖的package包/类
/**
 * 写入multipart中的一项
 *
 * @param out
 * @param name
 * @param value
 * @throws IOException
 */
private void writeEntry(OutputStream out, String name, Object value) throws IOException {
    writeLine(out, TWO_DASHES_BYTES, BOUNDARY_PREFIX_BYTES, boundaryPostfixBytes);

    String fileName = "";
    String contentType = null;
    if (value instanceof BodyItemWrapper) {
        BodyItemWrapper wrapper = (BodyItemWrapper) value;
        value = wrapper.getValue();
        fileName = wrapper.getFileName();
        contentType = wrapper.getContentType();
    }

    if (value instanceof File) {
        File file = (File) value;
        if (TextUtils.isEmpty(fileName)) {
            fileName = file.getName();
        }
        if (TextUtils.isEmpty(contentType)) {
            contentType = FileBody.getFileContentType(file);
        }
        writeLine(out, buildContentDisposition(name, fileName, charset));
        writeLine(out, buildContentType(value, contentType, charset));
        writeLine(out); // 内容前空一行
        writeFile(out, file);
        writeLine(out);
    } else {
        writeLine(out, buildContentDisposition(name, fileName, charset));
        writeLine(out, buildContentType(value, contentType, charset));
        writeLine(out); // 内容前空一行
        if (value instanceof InputStream) {
            writeStreamAndCloseIn(out, (InputStream) value);
            writeLine(out);
        } else {
            byte[] content;
            if (value instanceof byte[]) {
                content = (byte[]) value;
            } else {
                content = String.valueOf(value).getBytes(charset);
            }
            writeLine(out, content);
            current += content.length;
            if (callBackHandler != null && !callBackHandler.updateProgress(total, current, false)) {
                throw new Callback.CancelledException("upload stopped!");
            }
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:56,代码来源:MultipartBody.java

示例9: onCancelled

import org.xutils.common.Callback; //导入方法依赖的package包/类
protected void onCancelled(Callback.CancelledException cex) {
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:3,代码来源:AbsTask.java

示例10: doBackground

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
protected final ResultType doBackground() throws Throwable {
    this.onWaiting();
    PriorityRunnable runnable = new PriorityRunnable(
            task.getPriority(),
            new Runnable() {
                @Override
                public void run() {
                    try {
                        // 等待过程中取消
                        if (callOnCanceled || TaskProxy.this.isCancelled()) {
                            throw new Callback.CancelledException("");
                        }

                        // start running
                        TaskProxy.this.onStarted();

                        if (TaskProxy.this.isCancelled()) { // 开始时取消
                            throw new Callback.CancelledException("");
                        }

                        // 执行task, 得到结果.
                        task.setResult(task.doBackground());
                        TaskProxy.this.setResult(task.getResult());

                        // 未在doBackground过程中取消成功
                        if (TaskProxy.this.isCancelled()) {
                            throw new Callback.CancelledException("");
                        }

                        // 执行成功
                        TaskProxy.this.onSuccess(task.getResult());
                    } catch (Callback.CancelledException cex) {
                        TaskProxy.this.onCancelled(cex);
                    } catch (Throwable ex) {
                        TaskProxy.this.onError(ex, false);
                    } finally {
                        TaskProxy.this.onFinished();
                    }
                }
            });
    this.executor.execute(runnable);
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:45,代码来源:TaskProxy.java

示例11: onCancelled

import org.xutils.common.Callback; //导入方法依赖的package包/类
@Override
protected void onCancelled(Callback.CancelledException cex) {
    this.setState(State.CANCELLED);
    sHandler.obtainMessage(MSG_WHAT_ON_CANCEL, new ArgsObj(this, cex)).sendToTarget();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:TaskProxy.java

示例12: decodeFileWithLock

import org.xutils.common.Callback; //导入方法依赖的package包/类
/**
 * decode image file for ImageLoader
 *
 * @param file
 * @param options
 * @param cancelable
 * @return
 * @throws IOException
 */
/*package*/
static Drawable decodeFileWithLock(final File file,
                                   final ImageOptions options,
                                   final Callback.Cancelable cancelable) throws IOException {
    if (file == null || !file.exists() || file.length() < 1) return null;
    if (cancelable != null && cancelable.isCancelled()) {
        throw new Callback.CancelledException("cancelled during decode image");
    }

    Drawable result = null;
    if (!options.isIgnoreGif() && isGif(file)) {
        Movie movie = null;
        synchronized (gifDecodeLock) { // decode with lock
            movie = decodeGif(file, options, cancelable);
        }
        if (movie != null) {
            result = new GifDrawable(movie, (int) file.length());
        }
    } else {
        Bitmap bitmap = null;
        { // decode with lock
            try {
                while (bitmapDecodeWorker.get() >= BITMAP_DECODE_MAX_WORKER
                        && (cancelable == null || !cancelable.isCancelled())) {
                    synchronized (bitmapDecodeLock) {
                        try {
                            bitmapDecodeLock.wait();
                        } catch (InterruptedException iex) {
                            throw new Callback.CancelledException("cancelled during decode image");
                        } catch (Throwable ignored) {
                        }
                    }
                }

                if (cancelable != null && cancelable.isCancelled()) {
                    throw new Callback.CancelledException("cancelled during decode image");
                }

                bitmapDecodeWorker.incrementAndGet();
                // get from thumb cache
                if (options.isCompress()) {
                    bitmap = getThumbCache(file, options);
                }
                if (bitmap == null) {
                    bitmap = decodeBitmap(file, options, cancelable);
                    // save to thumb cache
                    if (bitmap != null && options.isCompress()) {
                        final Bitmap finalBitmap = bitmap;
                        THUMB_CACHE_EXECUTOR.execute(new Runnable() {
                            @Override
                            public void run() {
                                saveThumbCache(file, options, finalBitmap);
                            }
                        });
                    }
                }
            } finally {
                bitmapDecodeWorker.decrementAndGet();
                synchronized (bitmapDecodeLock) {
                    bitmapDecodeLock.notifyAll();
                }
            }
        }
        if (bitmap != null) {
            result = new ReusableBitmapDrawable(x.app().getResources(), bitmap);
        }
    }
    return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:79,代码来源:ImageDecoder.java

示例13: onCancelled

import org.xutils.common.Callback; //导入方法依赖的package包/类
public abstract void onCancelled(Callback.CancelledException cex); 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:2,代码来源:DownloadViewHolder.java


注:本文中的org.xutils.common.Callback.CancelledException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。