Android Open Source - EvokeFramework Main Activity






From Project

Back to project page EvokeFramework.

License

The source code is released under:

Apache License

If you think the Android project EvokeFramework 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 org.fs.net;
/*  w  w  w.java 2 s.c om*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import org.fs.net.evoke.DownloadManager;
import org.fs.net.evoke.data.RequestObject;

/**
 * Created by Fatih on 28/01/15.
 * as org.fs.net.MainActivity
 */
public class MainActivity extends Activity {
    
    private String urlString = "";
       
    ImageView imageView;
    
    long id;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        imageView = new ImageView(this);
        setContentView(imageView);        
        DownloadManager downloadManager = DownloadManager.getInstance(this);
        RequestObject.Builder builder = new RequestObject.Builder()
                .urlString("http://download.thinkbroadband.com/50MB.zip");  
        
        downloadManager.registerCallback(broadcast);
        id = downloadManager.enqueue(builder.build());
        //can cancel with this id or track the progress with this id.
    }

    DownloadManager.RequestCallback broadcast = new DownloadManager.RequestCallback() {
        
        long progress;


        /**
         * Progress of download manager request will be arrived here
         * @param id id of the current operations can be multiple up to 5 simultaneous
         * @param so is part we actually successfully downloaded in bytes.
         * @param total is the target value we actually going to reach in the future.
         */
        @Override
        public void onProgress(long id, long so, long total) {
            if(MainActivity.this.id == id) {
                if (total != 0) {
                    boolean newPercentage = progress != so * 100 / total;
                    if(newPercentage) {
                        progress = so * 100 / total;
                        Log.println(Log.ERROR,
                                MainActivity.class.getSimpleName(),
                                String.format("request : %d\nprogress: %d", id, progress));
                    }
                }
            }
        }

        /**
         * End of curtain download task from pool and where it is stored as string url 
         * accessible via new File(toUri) and get the obj. 
         * @param id id of operation completed.
         * @param toUri file's local uri.
         */
        @Override
        public void onComplete(long id, String toUri) {
            //data
        }

        /**
         * Error occur on the task at start most probably or on ongoing task 
         * @param id id of current request
         * @param urlString url string of the request that failed
         * @param reason reason integer from DownloadManager
         */
        @Override
        public void onError(long id, String urlString, int reason) {
            //if any progress started to download 1 byte or more it will remain until asked to resume for future keeping it that way more accurate if
            //mean time data will be changed that would not be lovely might need to add this as issue.. :/
        }
    };
}




Java Source Code List

org.fs.net.ApplicationTest.java
org.fs.net.MainActivity.java
org.fs.net.evoke.ApplicationTest.java
org.fs.net.evoke.DownloadManager.java
org.fs.net.evoke.core.AbstractObject.java
org.fs.net.evoke.data.Download.java
org.fs.net.evoke.data.Error.java
org.fs.net.evoke.data.HeadObject.java
org.fs.net.evoke.data.PartObject.java
org.fs.net.evoke.data.RequestObject.java
org.fs.net.evoke.database.DatabaseHelper.java
org.fs.net.evoke.listener.HeadCallback.java
org.fs.net.evoke.listener.PartCallback.java
org.fs.net.evoke.request.HeadRequest.java
org.fs.net.evoke.request.PartRequest.java
org.fs.net.evoke.th.AbstractRunnable.java
org.fs.net.evoke.util.JsonUtility.java
org.fs.net.evoke.util.LogUtil.java
org.fs.net.evoke.util.RequestUtility.java
org.fs.net.evoke.util.StringUtility.java
org.fs.net.evoke.util.Util.java