Browse Source

Merge branch 'master' of http://10.8.230.114:3000/kemllor/small_sheep_android

zhaoyi 8 years ago
parent
commit
76ae30252b
27 changed files with 1525 additions and 93 deletions
  1. 6 3
      app/build.gradle
  2. 8 1
      app/src/main/AndroidManifest.xml
  3. 23 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/BaseApplication.java
  4. 2 5
      app/src/main/java/com/sheep/jiuyan/samllsheep/Config.java
  5. 1 2
      app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java
  6. 230 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/adapter/DownListAdapter.java
  7. 48 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DefaultDownloadViewHolder.java
  8. 179 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadCallback.java
  9. 145 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadInfo.java
  10. 181 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadManager.java
  11. 0 28
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadService.java
  12. 35 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadState.java
  13. 28 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadStateConverter.java
  14. 41 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadViewHolder.java
  15. 1 1
      app/src/main/java/com/sheep/jiuyan/samllsheep/net/SheepCallback.java
  16. 8 8
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/DownloadActivity.java
  17. 1 1
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/GameDetailActivity.java
  18. 0 6
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/LoginActivity.java
  19. 56 35
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/MainActivity.java
  20. 1 1
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/TaskRecordActivity.java
  21. 72 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/XDownLoadActivity.java
  22. 2 1
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/adapter/AdpMainActivity.java
  23. 2 1
      app/src/main/java/com/sheep/jiuyan/samllsheep/page/fragment/FgtMainPageTask.java
  24. 347 0
      app/src/main/java/com/sheep/jiuyan/samllsheep/utils/ClassFileHelper.java
  25. 84 0
      app/src/main/res/layout/down_item.xml
  26. 7 0
      app/src/main/res/layout/download_activity.xml
  27. 17 0
      app/src/main/res/layout/x_download_activity.xml

+ 6 - 3
app/build.gradle

@@ -28,9 +28,9 @@ repositories {
 
 dependencies {
     /* compile fileTree(dir: 'libs', include: ['*.jar'])
-         androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
-             exclude group: 'com.android.support', module: 'support-annotations'
-         })*/
+             androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
+                 exclude group: 'com.android.support', module: 'support-annotations'
+             })*/
     compile 'com.android.support.constraint:constraint-layout:1.0.2'
     testCompile 'junit:junit:4.12'
     compile 'com.shark:screencapture:1.0.0'
@@ -47,4 +47,7 @@ dependencies {
     debugCompile 'com.readystatesoftware.chuck:library:1.1.0'
     compile 'de.hdodenhof:circleimageview:2.2.0'
     releaseCompile 'com.readystatesoftware.chuck:library-no-op:1.1.0'
+    compile 'org.xutils:xutils:3.5.0'
+    compile 'com.mylhyl:acp:1.1.7'
+    compile 'cn.yipianfengye.android:zxing-library:2.2'
 }

+ 8 - 1
app/src/main/AndroidManifest.xml

@@ -6,7 +6,6 @@
     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
     <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW"/>
     <uses-permission android:name="android.permission.REQUEST_MEDIA_PROJECTION"/>
-    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
@@ -16,6 +15,9 @@
     <uses-permission android:name="android.permission.GET_TASKS"/>
     <uses-permission android:name="android.permission.READ_LOGS"/>
 
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
 
     <permission
         android:name="android.permission.PACKAGE_USAGE_STATS"
@@ -27,6 +29,7 @@
         android:icon="@drawable/icon_app"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
+
         <activity
             android:name=".wxapi.WXEntryActivity"
             android:exported="true"
@@ -111,6 +114,10 @@
             android:name=".page.InputWXAccountActivity"
             android:screenOrientation="portrait"/>
         <activity android:name=".page.GameDetailActivity"/>
+
+        <activity
+            android:name=".page.XDownLoadActivity"
+            android:screenOrientation="portrait"/>
     </application>
 
 

+ 23 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/BaseApplication.java

@@ -0,0 +1,23 @@
+package com.sheep.jiuyan.samllsheep;
+
+import android.app.Application;
+
+import com.uuzuche.lib_zxing.activity.ZXingLibrary;
+
+import org.xutils.BuildConfig;
+import org.xutils.x;
+
+/**
+ * Created by Administrator on 2018/1/19.
+ */
+
+public class BaseApplication extends Application {
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        x.Ext.init(this);
+        x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能.
+        ZXingLibrary.initDisplayOpinion(this);
+    }
+}

+ 2 - 5
app/src/main/java/com/sheep/jiuyan/samllsheep/Config.java

@@ -14,12 +14,9 @@ public class Config {
     public static Config instance() {
         return mConfig;
     }
-
     public String mBaseUrl = "http://10.8.220.213:8088";
-
-    public String mHaoWanBaseUrl = "http://10.8.220.132:8082";
-    //    public String mBaseUrl = "http://api.task.bandaimi.com";
-    //    public String mBaseUrl = "http://test.ss.shouyouquan.com";
+//    public String mBaseUrl = "http://api.task.bandaimi.com";
+    //  public String mBaseUrl = "http://test.ss.shouyouquan.com";
     public final static String WX_APPID = "wx3c0376c4fcc8b723";
     public final static String BUGLY_APPID = "0dd998212c";
     public String[] mUrlList = new String[]{"http://10.8.220.213:8088", "http://test.ss.shouyouquan.com", "http://api.task.bandaimi.com"};

+ 1 - 2
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -1,7 +1,6 @@
 package com.sheep.jiuyan.samllsheep;
 
 import android.app.Activity;
-import android.app.Application;
 import android.content.Context;
 import android.os.Bundle;
 import android.util.DisplayMetrics;
@@ -19,7 +18,7 @@ import java.util.Map;
  * Created by kemllor on 2017/12/21.
  */
 
-public class SheepApp extends Application {
+public class SheepApp extends BaseApplication {
 
     public static Context mContext;
     public static IWXAPI mWxapi;

+ 230 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/adapter/DownListAdapter.java

@@ -0,0 +1,230 @@
+package com.sheep.jiuyan.samllsheep.adapter;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.bumptech.glide.Glide;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.download.DownloadInfo;
+import com.sheep.jiuyan.samllsheep.download.DownloadManager;
+import com.sheep.jiuyan.samllsheep.download.DownloadState;
+import com.sheep.jiuyan.samllsheep.download.DownloadViewHolder;
+import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
+
+import org.xutils.common.Callback;
+import org.xutils.ex.DbException;
+import org.xutils.x;
+
+import java.io.File;
+
+
+/**
+ * Created by Administrator on 2018/1/19.
+ */
+
+public class DownListAdapter extends BaseAdapter {
+    private Context mContext;
+    private final LayoutInflater mInflater;
+    private DownloadManager downloadManager;
+    public DownListAdapter(Context context) {
+        mContext=context;
+        mInflater=LayoutInflater.from(mContext);
+        downloadManager=DownloadManager.getInstance();
+    }
+
+    @Override
+    public int getCount() {
+        if (downloadManager == null) return 0;
+        return downloadManager.getDownloadListCount();
+    }
+
+    @Override
+    public Object getItem(int i) {
+        return downloadManager.getDownloadInfo(i);
+    }
+
+    @Override
+    public long getItemId(int i) {
+        return i;
+    }
+
+
+    @Override
+    public View getView(int i, View view, ViewGroup viewGroup) {
+        DownloadItemViewHolder holder = null;
+        DownloadInfo downloadInfo = downloadManager.getDownloadInfo(i);
+        if (view == null) {
+            view = mInflater.inflate(R.layout.down_item, null);
+            holder = new DownloadItemViewHolder(view, downloadInfo);
+            view.setTag(holder);
+            holder.refresh();
+        } else {
+            holder = (DownloadItemViewHolder) view.getTag();
+            holder.update(downloadInfo);
+        }
+
+        if (downloadInfo.getState().value() < DownloadState.FINISHED.value()) {
+            try {
+                downloadManager.startDownload(
+                        downloadInfo.getUrl(),
+                        downloadInfo.getLabel(),
+                        downloadInfo.getFileSavePath(),"",
+                        downloadInfo.isAutoResume(),
+                        downloadInfo.isAutoRename(),
+                        holder);
+            } catch (DbException ex) {
+                Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
+            }
+        }
+        return view;
+    }
+
+    class DownloadItemViewHolder extends DownloadViewHolder implements View.OnClickListener{
+
+        private ImageView ImageView;
+        private TextView  tv_game_name;
+        private TextView  tv_state;
+        private TextView  tv_remove;
+        private ProgressBar pb_download;
+        private TextView   tv_prorgess;
+
+        public DownloadItemViewHolder(View view, DownloadInfo downloadInfo) {
+            super(view, downloadInfo);
+            ImageView=(ImageView) view.findViewById(R.id.img_icon);
+            tv_game_name=(TextView) view.findViewById(R.id.tv_game_name);
+            tv_state=(TextView) view.findViewById(R.id.tv_state);
+            pb_download=(ProgressBar) view.findViewById(R.id.pb_download);
+            tv_remove=(TextView)view.findViewById(R.id.tv_remove);
+            tv_prorgess=(TextView) view.findViewById(R.id.tv_prorgess);
+            refresh();
+            Glide.with(mContext)
+                    .load(downloadInfo.getIcon())
+                    .placeholder(R.drawable.icon)
+                    .dontAnimate()
+                    .into(ImageView);
+            tv_state.setOnClickListener(this);
+            tv_remove.setOnClickListener(this);
+
+        }
+
+        @Override
+        public void update(DownloadInfo downloadInfo) {
+            super.update(downloadInfo);
+            refresh();
+        }
+
+        @Override
+        public void onWaiting() {
+            refresh();
+        }
+
+        @Override
+        public void onStarted() {
+            refresh();
+        }
+
+        @Override
+        public void onLoading(long total, long current) {
+            refresh();
+        }
+
+        @Override
+        public void onSuccess(File result) {
+            refresh();
+        }
+
+        @Override
+        public void onError(Throwable ex, boolean isOnCallback) {
+            refresh();
+        }
+
+        @Override
+        public void onCancelled(Callback.CancelledException cex) {
+            refresh();
+        }
+        public void refresh() {
+            tv_game_name.setText(downloadInfo.getLabel());
+            pb_download.setProgress(downloadInfo.getProgress());
+            tv_prorgess.setText(downloadInfo.getProgress()+"%");
+            DownloadState state = downloadInfo.getState();
+            switch (state) {
+                case WAITING:
+                case STARTED:
+                    tv_state.setText("暂停");
+                    break;
+                case ERROR:
+                case STOPPED:
+                    tv_state.setText("开始");
+                    break;
+                case FINISHED:
+                    PackageUtil.installApk(mContext, getDownloadInfo().getFileSavePath());
+                    tv_state.setText("完成");
+                    break;
+                default:
+                    tv_state.setText("开始");
+                    break;
+            }
+        }
+
+
+
+        @Override
+        public void onClick(View view) {
+             switch (view.getId()){
+                 case  R.id.tv_state:
+                     DownloadState state = downloadInfo.getState();
+                     switch (state) {
+                         case WAITING:
+                         case STARTED:
+                             downloadManager.stopDownload(downloadInfo);
+
+                             break;
+                         case ERROR:
+                         case STOPPED:
+                             try {
+                                 downloadManager.startDownload(
+                                         downloadInfo.getUrl(),
+                                         downloadInfo.getLabel(),
+                                         downloadInfo.getFileSavePath(),"",
+                                         downloadInfo.isAutoResume(),
+                                         downloadInfo.isAutoRename(),
+                                         this);
+                             } catch (DbException ex) {
+                                 Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
+                             }
+                             break;
+                         case FINISHED:
+                             Toast.makeText(x.app(), "已经下载完成", Toast.LENGTH_LONG).show();
+                             PackageUtil.installApk(mContext, getDownloadInfo().getFileSavePath());
+                             break;
+                         default:
+                             break;
+                     }
+                     break;
+                 case  R.id.tv_remove:
+                     try {
+                         downloadManager.removeDownload(downloadInfo);
+                          notifyDataSetChanged();
+                     } catch (DbException e) {
+                          Toast.makeText(x.app(), "移除任务失败", Toast.LENGTH_LONG).show();
+                     }
+                     break;
+             }
+        }
+    }
+
+
+    }
+
+
+
+
+
+

+ 48 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DefaultDownloadViewHolder.java

@@ -0,0 +1,48 @@
+package com.sheep.jiuyan.samllsheep.download;
+
+import android.view.View;
+import android.widget.Toast;
+
+import org.xutils.common.Callback;
+import org.xutils.x;
+
+import java.io.File;
+
+/**
+ * Created by wyouflf on 15/11/11.
+ */
+public class DefaultDownloadViewHolder extends DownloadViewHolder {
+
+    public DefaultDownloadViewHolder(View view, DownloadInfo downloadInfo) {
+        super(view, downloadInfo);
+    }
+
+    @Override
+    public void onWaiting() {
+
+    }
+
+    @Override
+    public void onStarted() {
+
+    }
+
+    @Override
+    public void onLoading(long total, long current) {
+
+    }
+
+    @Override
+    public void onSuccess(File result) {
+        Toast.makeText(x.app(), "下载完成", Toast.LENGTH_LONG).show();
+    }
+
+    @Override
+    public void onError(Throwable ex, boolean isOnCallback) {
+        Toast.makeText(x.app(), "下载失败", Toast.LENGTH_LONG).show();
+    }
+
+    @Override
+    public void onCancelled(Callback.CancelledException cex) {
+    }
+}

+ 179 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadCallback.java

@@ -0,0 +1,179 @@
+package com.sheep.jiuyan.samllsheep.download;
+
+import org.xutils.common.Callback;
+import org.xutils.common.util.LogUtil;
+import org.xutils.ex.DbException;
+
+import java.io.File;
+import java.lang.ref.WeakReference;
+
+/**
+ * Created by wyouflf on 15/11/10.
+ */
+/*package*/ class DownloadCallback implements
+        Callback.CommonCallback<File>,
+        Callback.ProgressCallback<File>,
+        Callback.Cancelable {
+
+    private DownloadInfo downloadInfo;
+    private WeakReference<DownloadViewHolder> viewHolderRef;
+    private DownloadManager downloadManager;
+    private boolean cancelled = false;
+    private Cancelable cancelable;
+
+    public DownloadCallback(DownloadViewHolder viewHolder) {
+        this.switchViewHolder(viewHolder);
+    }
+
+    public boolean switchViewHolder(DownloadViewHolder viewHolder) {
+        if (viewHolder == null) return false;
+
+        synchronized (DownloadCallback.class) {
+            if (downloadInfo != null) {
+                if (this.isStopped()) {
+                    return false;
+                }
+            }
+            this.downloadInfo = viewHolder.getDownloadInfo();
+            this.viewHolderRef = new WeakReference<DownloadViewHolder>(viewHolder);
+        }
+        return true;
+    }
+
+    public void setDownloadManager(DownloadManager downloadManager) {
+        this.downloadManager = downloadManager;
+    }
+
+    public void setCancelable(Cancelable cancelable) {
+        this.cancelable = cancelable;
+    }
+
+    private DownloadViewHolder getViewHolder() {
+        if (viewHolderRef == null) return null;
+        DownloadViewHolder viewHolder = viewHolderRef.get();
+        if (viewHolder != null) {
+            DownloadInfo downloadInfo = viewHolder.getDownloadInfo();
+            if (this.downloadInfo != null && this.downloadInfo.equals(downloadInfo)) {
+                return viewHolder;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public void onWaiting() {
+        try {
+            downloadInfo.setState(DownloadState.WAITING);
+            downloadManager.updateDownloadInfo(downloadInfo);
+        } catch (DbException ex) {
+            LogUtil.e(ex.getMessage(), ex);
+        }
+        DownloadViewHolder viewHolder = this.getViewHolder();
+        if (viewHolder != null) {
+            viewHolder.onWaiting();
+        }
+    }
+
+    @Override
+    public void onStarted() {
+        try {
+            downloadInfo.setState(DownloadState.STARTED);
+            downloadManager.updateDownloadInfo(downloadInfo);
+        } catch (DbException ex) {
+            LogUtil.e(ex.getMessage(), ex);
+        }
+        DownloadViewHolder viewHolder = this.getViewHolder();
+        if (viewHolder != null) {
+            viewHolder.onStarted();
+        }
+    }
+
+    @Override
+    public void onLoading(long total, long current, boolean isDownloading) {
+        if (isDownloading) {
+            try {
+                downloadInfo.setState(DownloadState.STARTED);
+                downloadInfo.setFileLength(total);
+                downloadInfo.setProgress((int) (current * 100 / total));
+                downloadManager.updateDownloadInfo(downloadInfo);
+            } catch (DbException ex) {
+                LogUtil.e(ex.getMessage(), ex);
+            }
+            DownloadViewHolder viewHolder = this.getViewHolder();
+            if (viewHolder != null) {
+                viewHolder.onLoading(total, current);
+            }
+        }
+    }
+
+    @Override
+    public void onSuccess(File result) {
+        synchronized (DownloadCallback.class) {
+            try {
+                downloadInfo.setState(DownloadState.FINISHED);
+                downloadManager.updateDownloadInfo(downloadInfo);
+            } catch (DbException ex) {
+                LogUtil.e(ex.getMessage(), ex);
+            }
+            DownloadViewHolder viewHolder = this.getViewHolder();
+            if (viewHolder != null) {
+                viewHolder.onSuccess(result);
+            }
+        }
+    }
+
+    @Override
+    public void onError(Throwable ex, boolean isOnCallback) {
+        synchronized (DownloadCallback.class) {
+            try {
+                downloadInfo.setState(DownloadState.ERROR);
+                downloadManager.updateDownloadInfo(downloadInfo);
+            } catch (DbException e) {
+                LogUtil.e(e.getMessage(), e);
+            }
+            DownloadViewHolder viewHolder = this.getViewHolder();
+            if (viewHolder != null) {
+                viewHolder.onError(ex, isOnCallback);
+            }
+        }
+    }
+
+    @Override
+    public void onCancelled(CancelledException cex) {
+        synchronized (DownloadCallback.class) {
+            try {
+                downloadInfo.setState(DownloadState.STOPPED);
+                downloadManager.updateDownloadInfo(downloadInfo);
+            } catch (DbException ex) {
+                LogUtil.e(ex.getMessage(), ex);
+            }
+            DownloadViewHolder viewHolder = this.getViewHolder();
+            if (viewHolder != null) {
+                viewHolder.onCancelled(cex);
+            }
+        }
+    }
+
+    @Override
+    public void onFinished() {
+        cancelled = false;
+    }
+
+    private boolean isStopped() {
+        DownloadState state = downloadInfo.getState();
+        return isCancelled() || state.value() > DownloadState.STARTED.value();
+    }
+
+    @Override
+    public void cancel() {
+        cancelled = true;
+        if (cancelable != null) {
+            cancelable.cancel();
+        }
+    }
+
+    @Override
+    public boolean isCancelled() {
+        return cancelled;
+    }
+}

+ 145 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadInfo.java

@@ -0,0 +1,145 @@
+package com.sheep.jiuyan.samllsheep.download;
+
+import org.xutils.db.annotation.Column;
+import org.xutils.db.annotation.Table;
+
+/**
+ * Author: wyouflf
+ * Date: 13-11-10
+ * Time: 下午8:11
+ */
+@Table(name = "download", onCreated = "CREATE UNIQUE INDEX index_name ON download(label,fileSavePath)")
+public class DownloadInfo {
+
+    public DownloadInfo() {
+    }
+
+    @Column(name = "id", isId = true)
+    private long id;
+
+    @Column(name = "state")
+    private DownloadState state = DownloadState.STOPPED;
+
+    @Column(name = "url")
+    private String url;
+
+    @Column(name = "Icon")
+    private String Icon;
+
+
+    @Column(name = "label")
+    private String label;
+
+    @Column(name = "fileSavePath")
+    private String fileSavePath;
+
+    @Column(name = "progress")
+    private int progress;
+
+    @Column(name = "fileLength")
+    private long fileLength;
+
+    @Column(name = "autoResume")
+    private boolean autoResume;
+
+    @Column(name = "autoRename")
+    private boolean autoRename;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public DownloadState getState() {
+        return state;
+    }
+
+    public void setState(DownloadState state) {
+        this.state = state;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public String getFileSavePath() {
+        return fileSavePath;
+    }
+
+    public void setFileSavePath(String fileSavePath) {
+        this.fileSavePath = fileSavePath;
+    }
+
+    public int getProgress() {
+        return progress;
+    }
+
+    public void setProgress(int progress) {
+        this.progress = progress;
+    }
+
+    public long getFileLength() {
+        return fileLength;
+    }
+
+    public void setFileLength(long fileLength) {
+        this.fileLength = fileLength;
+    }
+
+    public boolean isAutoResume() {
+        return autoResume;
+    }
+
+    public void setAutoResume(boolean autoResume) {
+        this.autoResume = autoResume;
+    }
+
+    public boolean isAutoRename() {
+        return autoRename;
+    }
+
+    public void setAutoRename(boolean autoRename) {
+        this.autoRename = autoRename;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof DownloadInfo)) return false;
+
+        DownloadInfo that = (DownloadInfo) o;
+
+        if (id != that.id) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return (int) (id ^ (id >>> 32));
+    }
+
+
+    public String getIcon() {
+        return Icon;
+    }
+
+    public void setIcon(String icon) {
+        Icon = icon;
+    }
+}

+ 181 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadManager.java

@@ -0,0 +1,181 @@
+package com.sheep.jiuyan.samllsheep.download;
+
+import org.xutils.DbManager;
+import org.xutils.common.Callback;
+import org.xutils.common.task.PriorityExecutor;
+import org.xutils.common.util.LogUtil;
+import org.xutils.db.converter.ColumnConverterFactory;
+import org.xutils.ex.DbException;
+import org.xutils.http.RequestParams;
+import org.xutils.x;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
+
+/**
+ * Author: wyouflf
+ * Date: 13-11-10
+ * Time: 下午8:10
+ */
+public final class DownloadManager {
+
+    static {
+        // 注册DownloadState在数据库中的值类型映射
+        ColumnConverterFactory.registerColumnConverter(DownloadState.class, new DownloadStateConverter());
+    }
+
+    private static volatile DownloadManager instance;
+
+    private final static int MAX_DOWNLOAD_THREAD = 2; // 有效的值范围[1, 3], 设置为3时, 可能阻塞图片加载.
+
+    private final DbManager db;
+    private final Executor executor = new PriorityExecutor(MAX_DOWNLOAD_THREAD, true);
+    private final List<DownloadInfo> downloadInfoList = new ArrayList<DownloadInfo>();
+    private final ConcurrentHashMap<DownloadInfo, DownloadCallback>
+            callbackMap = new ConcurrentHashMap<DownloadInfo, DownloadCallback>(5);
+
+    private DownloadManager() {
+        DbManager.DaoConfig daoConfig = new DbManager.DaoConfig()
+                .setDbName("download")
+                .setDbVersion(1);
+        db = x.getDb(daoConfig);
+        try {
+            List<DownloadInfo> infoList = db.selector(DownloadInfo.class).findAll();
+            if (infoList != null) {
+                for (DownloadInfo info : infoList) {
+                    if (info.getState().value() < DownloadState.FINISHED.value()) {
+                        info.setState(DownloadState.STOPPED);
+                    }
+                    downloadInfoList.add(info);
+                }
+            }
+        } catch (DbException ex) {
+            LogUtil.e(ex.getMessage(), ex);
+        }
+    }
+
+    /*package*/
+    public static DownloadManager getInstance() {
+        if (instance == null) {
+            synchronized (DownloadManager.class) {
+                if (instance == null) {
+                    instance = new DownloadManager();
+                }
+            }
+        }
+        return instance;
+    }
+
+    public void updateDownloadInfo(DownloadInfo info) throws DbException {
+        db.update(info);
+    }
+
+    public int getDownloadListCount() {
+        return downloadInfoList.size();
+    }
+
+    public DownloadInfo getDownloadInfo(int index) {
+        return downloadInfoList.get(index);
+    }
+
+    public synchronized void startDownload(String url, String label, String savePath,String imageUrl,
+                                           boolean autoResume, boolean autoRename,
+                                           DownloadViewHolder viewHolder) throws DbException {
+
+        String fileSavePath = new File(savePath).getAbsolutePath();
+        DownloadInfo downloadInfo = db.selector(DownloadInfo.class)
+                .where("label", "=", label)
+                .and("fileSavePath", "=", fileSavePath)
+                .findFirst();
+        if (downloadInfo != null) {
+            DownloadCallback callback = callbackMap.get(downloadInfo);
+            if (callback != null) {
+                if (viewHolder == null) {
+                    viewHolder = new DefaultDownloadViewHolder(null, downloadInfo);
+                }
+                if (callback.switchViewHolder(viewHolder)) {
+                    return;
+                } else {
+                    callback.cancel();
+                }
+            }
+        }
+
+        // create download info
+        if (downloadInfo == null) {
+            downloadInfo = new DownloadInfo();
+            downloadInfo.setUrl(url);
+            downloadInfo.setAutoRename(autoRename);
+            downloadInfo.setAutoResume(autoResume);
+            downloadInfo.setLabel(label);
+            downloadInfo.setFileSavePath(fileSavePath);
+            downloadInfo.setIcon(imageUrl);
+            downloadInfo.setState(DownloadState.STARTED);
+            db.saveBindingId(downloadInfo);
+        }
+
+        // start downloading
+        if (viewHolder == null) {
+            viewHolder = new DefaultDownloadViewHolder(null, downloadInfo);
+        } else {
+            viewHolder.update(downloadInfo);
+        }
+        DownloadCallback callback = new DownloadCallback(viewHolder);
+        callback.setDownloadManager(this);
+        callback.switchViewHolder(viewHolder);
+        RequestParams params = new RequestParams(url);
+        params.setAutoResume(downloadInfo.isAutoResume());
+        params.setAutoRename(downloadInfo.isAutoRename());
+        params.setSaveFilePath(downloadInfo.getFileSavePath());
+        params.setExecutor(executor);
+        params.setCancelFast(true);
+        Callback.Cancelable cancelable = x.http().get(params, callback);
+        callback.setCancelable(cancelable);
+        callbackMap.put(downloadInfo, callback);
+
+        if (downloadInfoList.contains(downloadInfo)) {
+            int index = downloadInfoList.indexOf(downloadInfo);
+            downloadInfoList.remove(downloadInfo);
+            downloadInfoList.add(index, downloadInfo);
+        } else {
+            downloadInfoList.add(downloadInfo);
+        }
+    }
+
+    public void stopDownload(int index) {
+        DownloadInfo downloadInfo = downloadInfoList.get(index);
+        stopDownload(downloadInfo);
+    }
+
+    public void stopDownload(DownloadInfo downloadInfo) {
+        Callback.Cancelable cancelable = callbackMap.get(downloadInfo);
+        if (cancelable != null) {
+            cancelable.cancel();
+        }
+    }
+
+    public void stopAllDownload() {
+        for (DownloadInfo downloadInfo : downloadInfoList) {
+            Callback.Cancelable cancelable = callbackMap.get(downloadInfo);
+            if (cancelable != null) {
+                cancelable.cancel();
+            }
+        }
+    }
+
+    public void removeDownload(int index) throws DbException {
+        DownloadInfo downloadInfo = downloadInfoList.get(index);
+        db.delete(downloadInfo);
+        stopDownload(downloadInfo);
+        downloadInfoList.remove(index);
+    }
+
+    public void removeDownload(DownloadInfo downloadInfo) throws DbException {
+        db.delete(downloadInfo);
+        stopDownload(downloadInfo);
+        downloadInfoList.remove(downloadInfo);
+    }
+}

+ 0 - 28
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadService.java

@@ -1,28 +0,0 @@
-package com.sheep.jiuyan.samllsheep.download;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-import android.support.annotation.Nullable;
-
-/**
- * Created by kemllor on 2017/12/26.
- */
-
-public class DownloadService extends Service {
-    @Nullable
-    @Override
-    public IBinder onBind(Intent intent) {
-        return null;
-    }
-
-    @Override
-    public void onCreate() {
-        super.onCreate();
-    }
-
-    @Override
-    public int onStartCommand(Intent intent, int flags, int startId) {
-        return super.onStartCommand(intent, flags, startId);
-    }
-}

+ 35 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadState.java

@@ -0,0 +1,35 @@
+package com.sheep.jiuyan.samllsheep.download;
+
+/**
+ * Created by wyouflf on 15/11/10.
+ */
+public enum DownloadState {
+    WAITING(0), STARTED(1), FINISHED(2), STOPPED(3), ERROR(4);
+
+    private final int value;
+
+    DownloadState(int value) {
+        this.value = value;
+    }
+
+    public int value() {
+        return value;
+    }
+
+    public static DownloadState valueOf(int value) {
+        switch (value) {
+            case 0:
+                return WAITING;
+            case 1:
+                return STARTED;
+            case 2:
+                return FINISHED;
+            case 3:
+                return STOPPED;
+            case 4:
+                return ERROR;
+            default:
+                return STOPPED;
+        }
+    }
+}

+ 28 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadStateConverter.java

@@ -0,0 +1,28 @@
+package com.sheep.jiuyan.samllsheep.download;
+
+import android.database.Cursor;
+
+import org.xutils.db.converter.ColumnConverter;
+import org.xutils.db.sqlite.ColumnDbType;
+
+/**
+ * Created by wyouflf on 15/11/10.
+ */
+public class DownloadStateConverter implements ColumnConverter<DownloadState> {
+
+    @Override
+    public DownloadState getFieldValue(Cursor cursor, int index) {
+        int dbValue = cursor.getInt(index);
+        return DownloadState.valueOf(dbValue);
+    }
+
+    @Override
+    public Object fieldValue2DbValue(DownloadState fieldValue) {
+        return fieldValue.value();
+    }
+
+    @Override
+    public ColumnDbType getColumnDbType() {
+        return ColumnDbType.INTEGER;
+    }
+}

+ 41 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/download/DownloadViewHolder.java

@@ -0,0 +1,41 @@
+package com.sheep.jiuyan.samllsheep.download;
+
+import android.view.View;
+
+import org.xutils.common.Callback;
+import org.xutils.x;
+
+import java.io.File;
+
+/**
+ * Created by wyouflf on 15/11/10.
+ */
+public abstract class DownloadViewHolder {
+
+    protected DownloadInfo downloadInfo;
+
+    public DownloadViewHolder(View view, DownloadInfo downloadInfo) {
+        this.downloadInfo = downloadInfo;
+        x.view().inject(this, view);
+    }
+
+    public final DownloadInfo getDownloadInfo() {
+        return downloadInfo;
+    }
+
+    public void update(DownloadInfo downloadInfo) {
+        this.downloadInfo = downloadInfo;
+    }
+
+    public abstract void onWaiting();
+
+    public abstract void onStarted();
+
+    public abstract void onLoading(long total, long current);
+
+    public abstract void onSuccess(File result);
+
+    public abstract void onError(Throwable ex, boolean isOnCallback);
+
+    public abstract void onCancelled(Callback.CancelledException cex);
+}

+ 1 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/net/SheepCallback.java

@@ -67,7 +67,7 @@ public abstract class SheepCallback<T> implements Callback {
     }
 
     public void otherCode(int code, String string) {
-//        Toast.makeText(SheepApp.mContext, string, Toast.LENGTH_SHORT).show();
+       Toast.makeText(SheepApp.mContext, string, Toast.LENGTH_SHORT).show();
         failure(new IOException(string));
     }
 

+ 8 - 8
app/src/main/java/com/sheep/jiuyan/samllsheep/page/DownloadActivity.java

@@ -6,6 +6,7 @@ import android.os.Environment;
 import android.os.SystemClock;
 import android.support.annotation.Nullable;
 import android.widget.ImageView;
+import android.widget.ListView;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
@@ -31,10 +32,7 @@ import java.io.File;
 
 public class DownloadActivity extends BaseActivity {
 
-
     private String DOWNLOAD_URL = "https://qiniu.kuaifazs.com/fszhskp_12493_haowan_2.1.2.apk";
-
-
     //    private TextView mTvDownload;
     private ProgressBar mPbDownload;
     private ImageView mImgIcon;
@@ -45,6 +43,8 @@ public class DownloadActivity extends BaseActivity {
     private String mPath;
     private String mApkPath;
     private BaseDownloadTask mDownloadTask;
+    private ListView lv;
+
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -91,6 +91,9 @@ public class DownloadActivity extends BaseActivity {
         TitleBarUtils.getInstance()
                 .setTitle(this,"任务下载")
                 .setTitleFinish(this);
+        lv=(ListView)findViewById(R.id.lv);
+
+
     }
 
 
@@ -113,19 +116,15 @@ public class DownloadActivity extends BaseActivity {
                         @Override
                         protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
                         }
-
                         @Override
                         protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
                             int percent = (int) ((double) soFarBytes / (double) totalBytes * 100);
                             mPbDownload.setProgress(percent);
                             mTvPercent.setText(percent + "%");
                         }
-
                         @Override
                         protected void blockComplete(BaseDownloadTask task) {
-
                         }
-
                         @Override
                         protected void completed(BaseDownloadTask task) {
                             PackageUtil.installApk(getApplicationContext(),mApkPath);
@@ -134,7 +133,6 @@ public class DownloadActivity extends BaseActivity {
 
                         @Override
                         protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {
-
                         }
 
                         @Override
@@ -144,6 +142,8 @@ public class DownloadActivity extends BaseActivity {
 
                         @Override
                         protected void warn(BaseDownloadTask task) {
+
+
                         }
                     });
 

+ 1 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/page/GameDetailActivity.java

@@ -112,7 +112,7 @@ public class GameDetailActivity extends BaseActivity {
                 if (PackageUtil.isAppInstalled(SheepApp.mContext, mTask.getTask().getPkg())) {
                     PackageUtil.startApp(SheepApp.mContext, mTask.getTask().getPkg());
                 } else {
-                    Intent intent = new Intent(GameDetailActivity.this, DownloadActivity.class);
+                    Intent intent = new Intent(GameDetailActivity.this, XDownLoadActivity.class);
                     intent.putExtra("task", mTask.getTask());
                     startActivity(intent);
                 }

+ 0 - 6
app/src/main/java/com/sheep/jiuyan/samllsheep/page/LoginActivity.java

@@ -174,12 +174,6 @@ public class LoginActivity extends BaseActivity {
             }
         });
 
-    /*    SendAuth.Req req = new SendAuth.Req();
-        req.scope = "snsapi_userinfo";
-        req.state = "small_sheep_auther";
-        SheepApp.mWxapi.sendReq(req);*/
-
-        //        SpUtils.login(this, "529e87ad4e1b49ebfffbd673fff48e01");
     }
 
 

+ 56 - 35
app/src/main/java/com/sheep/jiuyan/samllsheep/page/MainActivity.java

@@ -5,6 +5,7 @@ import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.SystemClock;
 import android.support.design.widget.AppBarLayout;
 import android.support.v4.app.ActivityCompat;
 import android.support.v4.content.ContextCompat;
@@ -12,11 +13,15 @@ import android.support.v4.view.ViewPager;
 import android.support.v4.widget.SwipeRefreshLayout;
 import android.util.Log;
 import android.view.View;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
 
 import com.bumptech.glide.Glide;
+import com.mylhyl.acp.Acp;
+import com.mylhyl.acp.AcpListener;
+import com.mylhyl.acp.AcpOptions;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.base.BaseActivity;
 import com.sheep.jiuyan.samllsheep.floatwindow.FloatWindow;
@@ -25,6 +30,7 @@ import com.sheep.jiuyan.samllsheep.page.fragment.FgtMainPageOffline;
 import com.sheep.jiuyan.samllsheep.page.fragment.FgtMainPageTask;
 import com.sheep.jiuyan.samllsheep.page.view.RappTabLayout;
 import com.sheep.jiuyan.samllsheep.service.TopService;
+import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.OpenService;
 import com.sheep.jiuyan.samllsheep.utils.PremissUtils;
@@ -75,44 +81,46 @@ public class MainActivity extends BaseActivity {
      * 申请读写权限6.0
      */
     private void getSA() {
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
-            return;
-        }
-        boolean has = PremissUtils.hasPermission(this);
-        if (!has) {
-            PremissUtils.openUsageAccessPage(this);
-        }
-        List<String> sa = new ArrayList<>();
-        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
-                != PackageManager.PERMISSION_GRANTED) {
-            sa.add(Manifest.permission.READ_PHONE_STATE);
-        }
-        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
-                != PackageManager.PERMISSION_GRANTED) {
-            sa.add(Manifest.permission.READ_EXTERNAL_STORAGE);
-        }
-        if (sa.size() < 1) {//如果都已经授权了,不能空列表去请求,否则报异常
-            return;
-        }
-    }
 
-    @Override
-    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
-        if (requestCode == INTENT_GET_PERMISSION) {
-            boolean isOk = true;
-            for (int result : grantResults) {
-                if (result == PackageManager.PERMISSION_DENIED) {
-                    isOk = false;
-                    break;//只要有一个拒绝,就退出并提示
-                }
-            }
-            if (!isOk) {
-                G.showToast("权限获取失败,部分功能可能无法正常工作。");
-            }
-        }
-        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+        Acp.getInstance(this).request(new AcpOptions.Builder()
+                        .setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
+                                , Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.READ_PHONE_STATE
+                        )
+                        .build(),
+                new AcpListener() {
+                    @Override
+                    public void onGranted() {
+                        ClassFileHelper.getInstance().createSDDirection();
+                    }
+                    @Override
+                    public void onDenied(List<String> permissions) {
+                        Toast.makeText(MainActivity.this,"亲!权限拒绝可能会导致某些功能无法使用",Toast.LENGTH_LONG).show();
+
+                    }
+                });
+
+
+
+
     }
 
+//    @Override
+//    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+//        if (requestCode == INTENT_GET_PERMISSION) {
+//            boolean isOk = true;
+//            for (int result : grantResults) {
+//                if (result == PackageManager.PERMISSION_DENIED) {
+//                    isOk = false;
+//                    break;//只要有一个拒绝,就退出并提示
+//                }
+//            }
+//            if (!isOk) {
+//                G.showToast("权限获取失败,部分功能可能无法正常工作。");
+//            }
+//        }
+//        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+//    }
+
 
     @Override
     protected int getLayoutId() {
@@ -203,6 +211,19 @@ public class MainActivity extends BaseActivity {
     @Override
     public void initView() {
         ((TextView) findViewById(R.id.txt_baseactivity_title)).setText("我的奖金");
+
+
+        Button btn= (Button) findViewById(R.id.btn_baseactivity_right);
+        btn.setBackgroundResource(R.drawable.icon_app);
+
+        btn.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                Intent i=new  Intent(MainActivity.this,XDownLoadActivity.class);
+                startActivity(i);
+            }
+        });
+
         mRappTabLayout = (RappTabLayout) findViewById(R.id.tab_main_activity);
         mViewPager = (ViewPager) findViewById(R.id.viewpager_main_activity);
         mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_main_activity);

+ 1 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/page/TaskRecordActivity.java

@@ -135,7 +135,7 @@ public class TaskRecordActivity extends BaseActivity {
                         EventBus.getDefault().post(floatMsg);*/
                         PackageUtil.startApp(getApplicationContext(), pkg);
                     } else {
-                        Intent intent = new Intent(TaskRecordActivity.this, DownloadActivity.class);
+                        Intent intent = new Intent(TaskRecordActivity.this, XDownLoadActivity.class);
                         intent.putExtra("task", commit.getTask());
                         startActivity(intent);
                     }

+ 72 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/page/XDownLoadActivity.java

@@ -0,0 +1,72 @@
+package com.sheep.jiuyan.samllsheep.page;
+
+import android.content.Intent;
+import android.os.Environment;
+import android.os.SystemClock;
+import android.widget.ListView;
+
+import com.bumptech.glide.Glide;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.adapter.DownListAdapter;
+import com.sheep.jiuyan.samllsheep.base.BaseActivity;
+import com.sheep.jiuyan.samllsheep.download.DownloadManager;
+import com.sheep.jiuyan.samllsheep.download.DownloadState;
+import com.sheep.jiuyan.samllsheep.page.entry.Task;
+import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
+import com.sheep.jiuyan.samllsheep.utils.FileUtil;
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
+
+import org.xutils.ex.DbException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Created by Administrator on 2018/1/22.
+ */
+
+public class XDownLoadActivity  extends BaseActivity {
+
+    private ListView  lv;
+    DownListAdapter  mAdapter;
+
+    @Override
+    protected int getLayoutId() {
+        return R.layout.download_activity;
+    }
+
+    @Override
+    public void initView() {
+        lv=(ListView)findViewById(R.id.lv);
+        TitleBarUtils.getInstance()
+                .setTitle(this,"任务下载")
+                .setTitleFinish(this);
+    }
+
+    @Override
+    public void initListener() {
+
+    }
+
+    @Override
+    public void initData() {
+        Intent intent = getIntent();
+        Task task = (Task) intent.getSerializableExtra("task");
+        if (task != null) {
+            ClassFileHelper.getInstance().createSDDirection();
+            File  mApkPath = new File(ClassFileHelper.DIR, task.getTitle()+ClassFileHelper.FILE_SUFFIX);
+            try {
+                DownloadManager.getInstance().startDownload(
+                        task.getDownLoadUrl(), task.getTitle(),
+                        mApkPath.getAbsolutePath(),task.getIcon(), true, false, null);
+            } catch (DbException e) {
+                e.printStackTrace();
+            }
+        }
+
+        mAdapter=new DownListAdapter(this);
+        lv.setAdapter(mAdapter);
+
+    }
+}

+ 2 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/page/adapter/AdpMainActivity.java

@@ -14,6 +14,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.page.DownloadActivity;
 import com.sheep.jiuyan.samllsheep.page.GameDetailActivity;
 import com.sheep.jiuyan.samllsheep.page.WebActivity;
+import com.sheep.jiuyan.samllsheep.page.XDownLoadActivity;
 import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
@@ -87,7 +88,7 @@ public class AdpMainActivity extends AdpCommonRecy<TaskPublish> {
             holder.getView(R.id.btn_task_item, TextView.class).setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
-                    Intent intent = new Intent(mContext, DownloadActivity.class);
+                    Intent intent = new Intent(mContext, XDownLoadActivity.class);
                     intent.putExtra("task", taskPublish.getTask());
                     mContext.startActivity(intent);
                 }

+ 2 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/page/fragment/FgtMainPageTask.java

@@ -24,6 +24,7 @@ import com.sheep.jiuyan.samllsheep.page.GameDetailActivity;
 import com.sheep.jiuyan.samllsheep.page.MoneyHistroyActivity;
 import com.sheep.jiuyan.samllsheep.page.TaskRecordActivity;
 import com.sheep.jiuyan.samllsheep.page.WebActivity;
+import com.sheep.jiuyan.samllsheep.page.XDownLoadActivity;
 import com.sheep.jiuyan.samllsheep.page.adapter.AdpMainActivity;
 import com.sheep.jiuyan.samllsheep.page.entry.TaskCount;
 import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
@@ -177,7 +178,7 @@ public class FgtMainPageTask extends BaseFragment {
                     if (PackageUtil.isAppInstalled(getActivity(), pkg)) {
                         PackageUtil.startApp(getActivity(), pkg);
                     } else {
-                        Intent intent = new Intent(getActivity(), DownloadActivity.class);
+                        Intent intent = new Intent(getActivity(), XDownLoadActivity.class);
                         intent.putExtra("task", mClickItem.getTask());
                         startActivity(intent);
                     }

+ 347 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/ClassFileHelper.java

@@ -0,0 +1,347 @@
+package com.sheep.jiuyan.samllsheep.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import android.content.Context;
+import android.os.Environment;
+import android.os.StatFs;
+
+/**
+ * Created by d on 2016/11/10.
+ * Method:
+ * getSDCardPath()
+ * getSDCardTotal() 总容量
+ * getSDCardFree() 可用容量
+ * createSDDirection()   创建目录
+ *deleteSDDirection  删除目录
+ * isFileExist 文件是否存在
+ * deleteSDFile  删除文件
+ * renameSDFile 修改文件或目录
+ * copySDFileTo 拷贝单个文件
+ * copySDFilesTo 拷贝所有
+ * moveSDFileTo 移动单个
+ * moveSDFilesTo 移动多个
+ * creatDataDirection 建立私有目录
+ * deleteDataFile 删除私有文件
+ * deleteDataDir 删除私有目录
+ * renameDataFile 修改私有文件名
+ * copyDataFileTo 私有目录下负责
+ * moveDataFileTo 移动私有文件
+ * moveDataFilesTo移动私有目录下所有文件
+ * deleteFile 删除文件
+ * deleteDirection 删除目录
+ * copyFileTo 拷贝
+ * copyFilesTo
+ * moveFileTo 移动
+ * moveFilesTo
+ *
+ */
+public class ClassFileHelper {
+    private static  String SDPATH= Environment.getExternalStorageDirectory().getAbsolutePath();
+    public  static  String FILE_SUFFIX=".apk";
+    public static   String DIR=Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"Sheep";
+    public  static  ClassFileHelper INSTANCE=new ClassFileHelper();
+
+    private ClassFileHelper( ){
+    }
+    public  static ClassFileHelper   getInstance( ){
+      return  INSTANCE;
+    }
+
+    //表示SDCard存在并且可以读写
+    public boolean isSDCardState(){
+        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
+            return true;
+        }else{
+            return false;
+        }
+    }
+
+    public  String gbEncoding(final String gbString) {
+        char[] utfBytes = gbString.toCharArray();   //utfBytes = [测, 试]
+        String unicodeBytes = "";
+        for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
+            String hexB = Integer.toHexString(utfBytes[byteIndex]);   //转换为16进制整型字符串
+            if (hexB.length() <= 2) {
+                hexB = "00" + hexB;
+            }
+            unicodeBytes = unicodeBytes + "\\u" + hexB;
+        }
+        System.out.println("unicodeBytes is: " + unicodeBytes);
+        return unicodeBytes;
+    }
+
+
+    /**
+     * 在SD卡上创建目录
+     *
+     *            要创建的目录名
+     * @return 创建得到的目录
+     */
+    public void createSDDirection() {
+        String status = Environment.getExternalStorageState();
+        if (status.equals(Environment.MEDIA_MOUNTED)) {
+            File dir = new File(DIR);
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+        }
+    }
+
+    /**
+     * 删除SD卡上的目录
+     *
+     * @param dirName
+     */
+    public boolean deleteSDDirection(String dirName) {
+        File dir = new File(SDPATH + dirName);
+        return deleteDirection(dir);
+    }
+
+    /**
+     * 判断文件是否已经存在
+     *
+     * @param fileName
+     *         要检查的文件名
+     * @return boolean, true表示存在,false表示不存在
+     */
+    public boolean isFileExist(String fileName) {
+        File file = new File(fileName);
+        return file.exists();
+    }
+
+    /**
+     * 删除SD卡上的文件
+     *
+     * @param fileName
+     */
+    public boolean deleteSDFile(String fileName) {
+        File file = new File(SDPATH + fileName);
+        if (file == null || !file.exists() || file.isDirectory())
+            return false;
+        file.delete();
+        return true;
+    }
+
+
+    /**
+     * 修改SD卡上的文件或目录名
+     *
+     * @param
+     */
+    public boolean renameSDFile(String oldfileName, String newFileName) {
+        File oleFile = new File(SDPATH + oldfileName);
+        File newFile = new File(SDPATH + newFileName);
+        return oleFile.renameTo(newFile);
+    }
+
+
+    /**
+     * 拷贝SD卡上的单个文件
+     *
+     * @param
+     * @throws IOException
+     */
+
+    public boolean copySDFileTo(String srcFileName, String destFileName) throws IOException {
+        File srcFile = new File(SDPATH + srcFileName);
+        File destFile = new File(SDPATH + destFileName);
+        return copyFileTo(srcFile, destFile);
+    }
+
+
+
+    /**
+     * 拷贝SD卡上指定目录的所有文件
+     *
+     * @param srcDirName
+     * @param destDirName
+     * @return
+     * @throws IOException
+     */
+    public boolean copySDFilesTo(String srcDirName, String destDirName) throws IOException {
+        File srcDir = new File(SDPATH + srcDirName);
+        File destDir = new File(SDPATH + destDirName);
+        return copyFilesTo(srcDir, destDir);
+    }
+
+
+
+    /**
+     * 移动SD卡上的单个文件
+     *
+     * @param srcFileName
+     * @param destFileName
+     * @return
+     * @throws IOException
+     */
+
+    public boolean moveSDFileTo(String srcFileName, String destFileName) throws IOException {
+        File srcFile = new File(SDPATH + srcFileName);
+        File destFile = new File(SDPATH + destFileName);
+        return moveFileTo(srcFile, destFile);
+    }
+
+
+
+    /**
+     * 移动SD卡上的指定目录的所有文件
+     *
+     * @param srcDirName
+     * @param destDirName
+     * @return
+     * @throws IOException
+     */
+
+    public boolean moveSDFilesTo(String srcDirName, String destDirName) throws IOException {
+        File srcDir = new File(SDPATH + srcDirName);
+        File destDir = new File(SDPATH + destDirName);
+        return moveFilesTo(srcDir, destDir);
+    }
+
+
+
+    /**
+     * 删除一个文件
+     *
+     * @param file
+     * @return
+     */
+
+    public boolean deleteFile(File file) {
+        if (file.isDirectory())
+            return false;
+        return file.delete();
+    }
+
+    /**
+     * 删除一个目录(可以是非空目录)
+     *
+     * @param dir
+     */
+
+    public boolean deleteDirection(File dir) {
+        if (dir == null || !dir.exists() || dir.isFile()) {
+            return false;
+        }
+        for (File file : dir.listFiles()) {
+            if (file.isFile()) {
+                file.delete();
+            } else if (file.isDirectory()) {
+                deleteDirection(file);// 递归
+            }
+        }
+        dir.delete();
+        return true;
+    }
+
+    /**
+     * 拷贝一个文件,srcFile源文件,destFile目标文件
+     *
+     * @param
+     * @throws IOException
+     */
+
+    public boolean copyFileTo(File srcFile, File destFile) throws IOException {
+
+        if (srcFile.isDirectory() || destFile.isDirectory())
+            return false;// 判断是否是文件
+        FileInputStream fis = new FileInputStream(srcFile);
+        FileOutputStream fos = new FileOutputStream(destFile);
+        int readLen = 0;
+        byte[] buf = new byte[1024];
+        while ((readLen = fis.read(buf)) != -1) {
+            fos.write(buf, 0, readLen);
+        }
+        fos.flush();
+        fos.close();
+        fis.close();
+        return true;
+    }
+
+    /**
+     * 拷贝目录下的所有文件到指定目录
+     *
+     * @param srcDir
+     * @param destDir
+     * @return
+     * @throws IOException
+     */
+
+    public boolean copyFilesTo(File srcDir, File destDir) throws IOException {
+
+        if (!srcDir.isDirectory() || !destDir.isDirectory())
+            return false;// 判断是否是目录
+        if (!destDir.exists())
+            return false;// 判断目标目录是否存在
+        File[] srcFiles = srcDir.listFiles();
+        for (int i = 0; i < srcFiles.length; i++) {
+            if (srcFiles[i].isFile()) {
+                // 获得目标文件
+                File destFile = new File(destDir.getPath() + "//"
+                        + srcFiles[i].getName());
+                copyFileTo(srcFiles[i], destFile);
+            } else if (srcFiles[i].isDirectory()) {
+                File theDestDir = new File(destDir.getPath() + "//"
+                        + srcFiles[i].getName());
+                copyFilesTo(srcFiles[i], theDestDir);
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 移动一个文件
+     *
+     * @param srcFile
+     * @param destFile
+     * @return
+     * @throws IOException
+     */
+
+    public boolean moveFileTo(File srcFile, File destFile) throws IOException {
+
+        boolean is_copy = copyFileTo(srcFile, destFile);
+
+        if (!is_copy)
+            return false;
+        deleteFile(srcFile);
+        return true;
+    }
+
+    /**
+     * 移动目录下的所有文件到指定目录
+     *
+     * @param srcDir
+     * @param destDir
+     * @return
+     * @throws IOException
+     */
+
+    public boolean moveFilesTo(File srcDir, File destDir) throws IOException {
+        if (!srcDir.isDirectory() || !destDir.isDirectory()) {
+            return false;
+        }
+
+        File[] srcDirFiles = srcDir.listFiles();
+        for (int i = 0; i < srcDirFiles.length; i++) {
+            if (srcDirFiles[i].isFile()) {
+                File oneDestFile = new File(destDir.getPath() + "//"
+                        + srcDirFiles[i].getName());
+                moveFileTo(srcDirFiles[i], oneDestFile);
+                deleteFile(srcDirFiles[i]);
+            } else if (srcDirFiles[i].isDirectory()) {
+                File oneDestFile = new File(destDir.getPath() + "//"
+                        + srcDirFiles[i].getName());
+                moveFilesTo(srcDirFiles[i], oneDestFile);
+                deleteDirection(srcDirFiles[i]);
+            }
+        }
+        return true;
+    }
+}

+ 84 - 0
app/src/main/res/layout/down_item.xml

@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="50dp"
+        android:layout_marginTop="10dp">
+
+
+        <ImageView
+            android:id="@+id/img_icon"
+            android:layout_width="50dp"
+            android:layout_height="50dp"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="10dp"
+            android:src="@drawable/icon_sheep"
+            />
+
+
+        <TextView
+            android:id="@+id/tv_game_name"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="10dp"
+            android:layout_toRightOf="@id/img_icon"
+            android:text="2019-12-26"
+            android:textColor="@color/black_dark"/>
+
+        <TextView
+            android:id="@+id/tv_prorgess"
+            android:textColor="@color/theme"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentRight="true"
+            android:textSize="16sp"
+            android:text="30%"
+            android:layout_marginTop="10dp"
+            android:layout_marginRight="10dp"
+            />
+
+
+       <LinearLayout
+           android:layout_width="wrap_content"
+           android:layout_height="wrap_content"
+           android:orientation="horizontal"
+           android:layout_alignParentBottom="true"
+           android:layout_alignParentRight="true"
+           android:layout_centerVertical="true"
+           android:layout_marginRight="10dp"
+           android:layout_marginTop="10dp"
+           >
+        <TextView
+            android:id="@+id/tv_state"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:padding="5dp"
+            android:text="开始"
+            android:textColor="@color/theme"/>
+           <TextView
+               android:id="@+id/tv_remove"
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:padding="5dp"
+               android:text="删除"
+               android:textColor="@color/theme"/>
+       </LinearLayout>
+    </RelativeLayout>
+
+    <ProgressBar
+        android:id="@+id/pb_download"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="10dp"
+        android:layout_marginRight="10dp"
+        android:progress="3"
+        />
+
+</LinearLayout>

+ 7 - 0
app/src/main/res/layout/download_activity.xml

@@ -7,6 +7,13 @@
     <include
         layout="@layout/title"/>
 
+
+     <ListView
+         android:id="@+id/lv"
+         android:layout_width="match_parent"
+         android:layout_height="match_parent"></ListView>
+
+
     <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="50dp"

+ 17 - 0
app/src/main/res/layout/x_download_activity.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent"
+              android:orientation="vertical">
+
+    <include
+        layout="@layout/title"/>
+
+
+     <ListView
+         android:id="@+id/lv"
+         android:layout_width="match_parent"
+         android:layout_height="match_parent"></ListView>
+
+
+</LinearLayout>