zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    教您搭建与布署NTP网络时钟服务器
    利用北斗卫星系统设计NTP网络时间服务器
    GPS同步时钟(北斗时间服务器)守时方法研究
    京准讲述NTP时钟服务器应用及原理
    标准化考场时钟系统(电子时钟)时间同步设备
    北斗授时产品详解与应用
    IRIG-B码对时是变电站自动化系统的基本要求
    北斗同步时钟(主时钟控制器)应用于电气化铁道远动系统
    IEEE1588PTP在数字化变电站时钟同步方面的应用
    thinkphp6学习教程与源码 tp6开源CMS系统源码研究
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5131648.html
Copyright © 2011-2022 走看看