parent
041df07617
commit
b8a86890a7
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.arialyy.aria.core.queue.pool; |
||||||
|
|
||||||
|
import com.arialyy.aria.core.AriaManager; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Aria.Lao on 2017/7/17. |
||||||
|
* 下载任务池,该池子为简单任务和任务组共用 |
||||||
|
*/ |
||||||
|
public class DownloadSharePool { |
||||||
|
private static volatile DownloadSharePool INSTANCE; |
||||||
|
|
||||||
|
public DownloadExecutePool executePool; |
||||||
|
public BaseCachePool cachePool; |
||||||
|
|
||||||
|
private DownloadSharePool() { |
||||||
|
executePool = new DownloadExecutePool<>(); |
||||||
|
cachePool = new BaseCachePool<>(); |
||||||
|
} |
||||||
|
|
||||||
|
public static DownloadSharePool getInstance() { |
||||||
|
if (INSTANCE == null) { |
||||||
|
synchronized (AriaManager.LOCK) { |
||||||
|
INSTANCE = new DownloadSharePool(); |
||||||
|
} |
||||||
|
} |
||||||
|
return INSTANCE; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.arialyy.aria.core.queue.pool; |
||||||
|
|
||||||
|
import com.arialyy.aria.core.AriaManager; |
||||||
|
import com.arialyy.aria.core.inf.AbsTask; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Aria.Lao on 2017/7/17. |
||||||
|
*/ |
||||||
|
public class UploadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> { |
||||||
|
@Override protected int getMaxSize() { |
||||||
|
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.arialyy.aria.core.queue.pool; |
||||||
|
|
||||||
|
import com.arialyy.aria.core.AriaManager; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Aria.Lao on 2017/7/17. |
||||||
|
* 下载任务池,该池子为简单任务和任务组共用 |
||||||
|
*/ |
||||||
|
public class UploadSharePool { |
||||||
|
private static volatile UploadSharePool INSTANCE; |
||||||
|
|
||||||
|
public UploadExecutePool executePool; |
||||||
|
public BaseCachePool cachePool; |
||||||
|
|
||||||
|
private UploadSharePool() { |
||||||
|
executePool = new UploadExecutePool(); |
||||||
|
cachePool = new BaseCachePool<>(); |
||||||
|
} |
||||||
|
|
||||||
|
public static UploadSharePool getInstance() { |
||||||
|
if (INSTANCE == null) { |
||||||
|
synchronized (AriaManager.LOCK) { |
||||||
|
INSTANCE = new UploadSharePool(); |
||||||
|
} |
||||||
|
} |
||||||
|
return INSTANCE; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,92 @@ |
|||||||
|
package com.arialyy.simple.widget; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import android.support.annotation.Nullable; |
||||||
|
import android.util.AttributeSet; |
||||||
|
import android.view.LayoutInflater; |
||||||
|
import android.view.View; |
||||||
|
import android.widget.LinearLayout; |
||||||
|
import android.widget.TextView; |
||||||
|
import com.arialyy.aria.core.download.DownloadEntity; |
||||||
|
import com.arialyy.simple.R; |
||||||
|
import java.util.LinkedList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Aria.Lao on 2017/7/17. |
||||||
|
*/ |
||||||
|
public class SubStateLinearLayout extends LinearLayout { |
||||||
|
|
||||||
|
List<DownloadEntity> mSubData = new LinkedList<>(); |
||||||
|
|
||||||
|
public SubStateLinearLayout(Context context) { |
||||||
|
super(context); |
||||||
|
} |
||||||
|
|
||||||
|
public SubStateLinearLayout(Context context, @Nullable AttributeSet attrs) { |
||||||
|
super(context, attrs); |
||||||
|
} |
||||||
|
|
||||||
|
public SubStateLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
||||||
|
super(context, attrs, defStyleAttr); |
||||||
|
} |
||||||
|
|
||||||
|
public void addData(List<DownloadEntity> datas) { |
||||||
|
removeAllViews(); |
||||||
|
mSubData.clear(); |
||||||
|
mSubData.addAll(datas); |
||||||
|
createShowView(); |
||||||
|
int i = 1; |
||||||
|
for (DownloadEntity entity : datas) { |
||||||
|
TextView view = createView(entity); |
||||||
|
addView(view, i); |
||||||
|
i++; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void update(DownloadEntity entity) { |
||||||
|
int position = mSubData.indexOf(entity) + 1; |
||||||
|
if (position != 0) { |
||||||
|
((TextView) getChildAt(position)).setText(entity.getFileName() + ": " + getPercent(entity)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private TextView createView(DownloadEntity entity) { |
||||||
|
TextView view = |
||||||
|
(TextView) LayoutInflater.from(getContext()).inflate(R.layout.layout_child_state, null); |
||||||
|
view.setText(entity.getFileName() + ": " + getPercent(entity)); |
||||||
|
return view; |
||||||
|
} |
||||||
|
|
||||||
|
private void createShowView() { |
||||||
|
|
||||||
|
TextView view = |
||||||
|
(TextView) LayoutInflater.from(getContext()).inflate(R.layout.layout_child_state, null); |
||||||
|
view.setText("点击显示子任务"); |
||||||
|
view.setOnClickListener(new OnClickListener() { |
||||||
|
@Override public void onClick(View v) { |
||||||
|
if (getVisibility() == GONE) { |
||||||
|
showChild(true); |
||||||
|
((TextView) v).setText("点击隐藏子任务"); |
||||||
|
} else { |
||||||
|
showChild(false); |
||||||
|
((TextView) v).setText("点击显示子任务"); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
addView(view, 0); |
||||||
|
} |
||||||
|
|
||||||
|
private void showChild(boolean show) { |
||||||
|
for (int i = 1, count = getChildCount(); i < count; i++) { |
||||||
|
getChildAt(i).setVisibility(show ? VISIBLE : GONE); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private int getPercent(DownloadEntity entity) { |
||||||
|
long size = entity.getFileSize(); |
||||||
|
long progress = entity.getCurrentProgress(); |
||||||
|
int current = size == 0 ? 0 : (int) (progress * 100 / size); |
||||||
|
return current; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:padding="8dp" |
||||||
|
android:textColor="@color/black" |
||||||
|
android:textSize="20sp" |
||||||
|
/> |
Loading…
Reference in new issue