码迷,mamicode.com
首页 > 移动开发 > 详细

Android studio ElasticDownloadView

时间:2015-06-30 13:07:12      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:androidstudio   elasticdownloadview   

找到个开源项目,地址:https://github.com/Tibolte/ElasticDownload

下载进度效果:

技术分享


builde.gradle:

  

 compile 'com.github.tibolte:elasticdownload:1.0.+'

测试代码如下:BaseActivity.java

                    

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

import com.lidroid.xutils.ViewUtils;

/**
 * Created by LanYan on 2015/6/29.
 */
public abstract class BasicActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        config();
        setContentView(getLayoutID());
        //Annotations view
        ViewUtils.inject(this);
        initView();
    }

    /*
    * The annotation of the control of the UI update
    * Method is protected ,child activity super..
    * */
    protected void initView() {
    }

    /*
    * Config application theme style,such as no title bar, or status bar, transparent, etc
    * Method is protected,child activity super ..
    **/
    protected void config() {

    }

    /*
    * Build contentView id
    * onCreate(Bundle saveInstanceState)>setContentView(R.layout.activity_main)
    * R.layout.activity_main=getlayoutId();
    * */
    public abstract int getLayoutID();


    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        super.onResume();
    }
}

MainActivity.java


import android.view.View;
import android.view.Window;
import android.widget.Button;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import java.io.File;

import is.arontibo.library.ElasticDownloadView;

/**
 * Created by LanYan on 2015/6/29.
 */
public class MainActivity extends BasicActivity {

    @ViewInject(R.id.startDownload)
    private Button startDownload;

    @ViewInject(R.id.elastic_download_view)
    private ElasticDownloadView mDownloadView;

    @Override
    protected void config() {
        super.config();
        requestWindowFeature(Window.FEATURE_NO_TITLE);
       /* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_main;
    }

    @OnClick(R.id.startDownload)
    public void onClick(View v) {
        String url = "http://img0.bdstatic.com/img/image/6446027056db8afa73b23eaf953dadde1410240902.jpg";
        String tagUrl="/sdcard/download/6446027056db8afa73b23eaf953dadde1410240902.jpg";
        new HttpUtils().download( url,tagUrl, false, getListener());

    }

    protected RequestCallBack<File> getListener() {
        return new RequestCallBack<File>() {

            @Override
            public void onStart() {
                super.onStart();
                mDownloadView.startIntro();
            }

            @Override
            public void onLoading(long total, long current, boolean isUploading) {
                super.onLoading(total, current, isUploading);
                mDownloadView.setProgress(current/total*100);
            }

            @Override
            public void onCancelled() {
                super.onCancelled();
                mDownloadView.fail();
            }

            @Override
            public void onSuccess(ResponseInfo<File> responseInfo) {
                mDownloadView.success();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                mDownloadView.fail();
            }
        };
    }
}


界面颜色配置参照Library value color:


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="orange_salmon">#EC5745</color>
    <color name="red_wine">#A6463A</color>
    <color name="red_wood">#4B1D17</color>
    <color name="green_grass">#109121</color>
</resources>


备注:该测试demo用android studio 开发的,如果需要转换成Eclipse project,需要下载相关依赖:

技术分享

同时要注意版本要求:Android v2.2+,个别特效只支持Api14+ 


demo下载地址:http://download.csdn.net/detail/anddroid_lanyan/8853065

版权声明:本文为博主原创文章,未经博主允许不得转载。

Android studio ElasticDownloadView

标签:androidstudio   elasticdownloadview   

原文地址:http://blog.csdn.net/anddroid_lanyan/article/details/46692109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!