Android Open Source - AndroidUploader Upload Ui Handler






From Project

Back to project page AndroidUploader.

License

The source code is released under:

Apache License

If you think the Android project AndroidUploader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package z.hol.uploader;
//from w  w w.j  a  va 2s  . c o  m
import android.os.Handler;
import android.os.Message;

/**
 * ui???
 * Created by holmes on 10/19/14.
 */
public abstract class UploadUiHandler extends Handler implements UploadStateCallback{
    private static final int CODE_FINISHDE = 1;
    private static final int CODE_ERROR = 2;
    private static final int CODE_COMPLETED = 3;
    private static final int CODE_PROGRESS = 4;
    private static final int CODE_CANCEL = 5;
    private static final int CODE_START = 6;

    @Override
    public void handleMessage(Message msg) {
        int id = msg.arg1;
        switch (msg.what){
            case CODE_COMPLETED:
                onCompleted(id);
                break;
            case CODE_FINISHDE:
                onUploadFinished(id);
                break;
            case CODE_CANCEL:
                onCancel(id);
                break;
            case CODE_ERROR:
                int[] errorCode = (int[]) msg.obj;
                onError(id, errorCode[0]);
                break;
            case CODE_START:
                onUploadStart(id);
                break;
            case CODE_PROGRESS:
                long[] pro = (long[]) msg.obj;
                onProgress(id, pro[0], pro[1]);
                break;
        }

    }

    protected void sendMessageToTarge(Message msg){
        this.sendMessage(msg);
    }

    /**
     * ???
     * @param id
     */
    void uploadStart(int id){
        Message msg = Message.obtain();
        msg.what = CODE_START;
        msg.arg1 = id;
        sendMessageToTarge(msg);
    }

    /**
     * ??????????????, ???????????
     */
    void uploadFinished(int id){
        Message msg = Message.obtain();
        msg.what = CODE_FINISHDE;
        msg.arg1 = id;
        sendMessageToTarge(msg);

    }

    /**
     * ??
     * @param code
     */
    void error(int id, int code){
        Message msg = Message.obtain();
        msg.what = CODE_ERROR;
        msg.arg1 = id;
        msg.obj = new int[]{code};
        sendMessageToTarge(msg);

    }

    /**
     * ???
     */
    void completed(int id){
        Message msg = Message.obtain();
        msg.what = CODE_COMPLETED;
        msg.arg1 = id;
        sendMessageToTarge(msg);

    }

    /**
     * ??
     * @param total
     * @param current
     */
    void progress(int id, long total, long current){
        Message msg = Message.obtain();
        msg.what = CODE_PROGRESS;
        msg.arg1 = id;
        msg.obj = new long[]{total, current};
        sendMessageToTarge(msg);

    }

    /**
     * ?????
     */
    void cancel(int id){
        Message msg = Message.obtain();
        msg.what = CODE_CANCEL;
        msg.arg1 = id;
        sendMessageToTarge(msg);
    }
}




Java Source Code List

z.hol.uploader.FileHttpUploader.java
z.hol.uploader.HttpUploader.java
z.hol.uploader.StreamUploader.java
z.hol.uploader.UploadStateCallback.java
z.hol.uploader.UploadUiHandler.java
z.hol.uploader.Uploader.java
z.hol.uploader.bridge.Bridge.java
z.hol.uploader.bridge.HttpBridge.java
z.hol.uploader.bridge.StreamBridge.java