• Android studio 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

  • 相关阅读:
    linux 如何显示一个文件的某几行(中间几行)
    Cookie——Javascript
    CSS——4种定位
    Javascript——DOM
    javascript之八——BOM
    Javascript——闭包、作用域链
    Struct2
    javaweb——Servlet作为控制器
    排序算法——快排思想
    java——获取从控制台输入的数据的方法
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5131648.html
Copyright © 2020-2023  润新知