From 22943e508a6425b6c7c1f9e4be217d098c2c93de Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 21 Mar 2017 11:04:47 +0800 Subject: [PATCH 1/2] .. --- .idea/modules.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.idea/modules.xml b/.idea/modules.xml index b0a774eb..9f4bd159 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,8 +2,10 @@ + + From eee6f45471a522c3334e7b492520bcfdb4b5df48 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 21 Mar 2017 18:11:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/arialyy/aria/util/FileUtil.java | 103 ++++++++++++++++++ .../aria/window/AriaFileChangeActivity.java | 55 ++++++++++ .../aria/window/FileChangeAdapter.java | 77 +++++++++++++ .../com/arialyy/aria/window/FileEntity.java | 14 +++ .../res/layout/activity_aria_file_shange.xml | 14 +++ Aria/src/main/res/layout/item_file.xml | 51 +++++++++ Aria/src/main/res/values/strings.xml | 2 +- 7 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/util/FileUtil.java create mode 100644 Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java create mode 100644 Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java create mode 100644 Aria/src/main/java/com/arialyy/aria/window/FileEntity.java create mode 100644 Aria/src/main/res/layout/activity_aria_file_shange.xml create mode 100644 Aria/src/main/res/layout/item_file.xml diff --git a/Aria/src/main/java/com/arialyy/aria/util/FileUtil.java b/Aria/src/main/java/com/arialyy/aria/util/FileUtil.java new file mode 100644 index 00000000..9dcf77c6 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/util/FileUtil.java @@ -0,0 +1,103 @@ +package com.arialyy.aria.util; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; +import com.arialyy.aria.window.FileEntity; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Aria.Lao on 2017/3/21. + */ + +public class FileUtil { + + Context mContext; + + public FileUtil(Context context) { + mContext = context; + } + + /** + * 文件列表 + */ + public List loadFiles(String path) { + File file = new File(path); + File[] files = file.listFiles(); + List list = new ArrayList<>(); + for (File f : files) { + FileEntity entity = new FileEntity(); + entity.fileName = f.getName(); + //entity.fileInfo = getFileType(f.getPath()); + //entity.fileDrawable = getApkIcon(mContext, f.getPath()); + list.add(entity); + } + return list; + } + + /** + * 获取文件类型 + */ + public FileType getFileType(String path) { + String exName = getExName(path); + String type = ""; + FileType fType = null; + if (exName.equalsIgnoreCase("apk")) { + fType = new FileType("应用", getApkIcon(path)); + } else if (exName.equalsIgnoreCase("img") + || exName.equalsIgnoreCase("png") + || exName.equalsIgnoreCase("jpg") + || exName.equalsIgnoreCase("jepg")) { + //fType = new FileType("图片", ) + } else if (exName.equalsIgnoreCase("mp3") || exName.equalsIgnoreCase("wm")) { + //fType = new FileType("音乐", ); + } else if (exName.equalsIgnoreCase("mp4") + || exName.equalsIgnoreCase("rm") + || exName.equalsIgnoreCase("rmvb")) { + //fType = new FileType("视频", ); + } return fType; + } + + /** + * 获取扩展名 + */ + public String getExName(String path) { + int separatorIndex = path.lastIndexOf("."); + return (separatorIndex < 0) ? path : path.substring(separatorIndex + 1, path.length()); + } + + /** + * 获取apk文件的icon + * + * @param path apk文件路径 + */ + public Drawable getApkIcon(String path) { + PackageManager pm = mContext.getPackageManager(); + PackageInfo info = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES); + if (info != null) { + ApplicationInfo appInfo = info.applicationInfo; + //android有bug,需要下面这两句话来修复才能获取apk图片 + appInfo.sourceDir = path; + appInfo.publicSourceDir = path; + // String packageName = appInfo.packageName; //得到安装包名称 + // String version=info.versionName; //得到版本信息 + return pm.getApplicationIcon(appInfo); + } + return null; + } + + class FileType { + String name; + Drawable icon; + + public FileType(String name, Drawable icon) { + this.name = name; + this.icon = icon; + } + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java b/Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java new file mode 100644 index 00000000..a0da30e5 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java @@ -0,0 +1,55 @@ +package com.arialyy.aria.window; + +import android.os.Bundle; +import android.os.Environment; +import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; +import android.widget.AbsListView; +import android.widget.ListView; +import com.arialyy.aria.R; +import com.arialyy.aria.util.FileUtil; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by Aria.Lao on 2017/3/21. + * 文件选择 + */ +public class AriaFileChangeActivity extends FragmentActivity { + final String ROOT_PAT = Environment.getExternalStorageDirectory().getPath(); + ListView mList; + FileChangeAdapter mAdapter; + Map> mData = new HashMap<>(); + private String mCurrentPath = ROOT_PAT; + + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_aria_file_shange); + mList = (ListView) findViewById(R.id.list); + mList.setOnScrollListener(new AbsListView.OnScrollListener() { + int state; + + @Override public void onScrollStateChanged(AbsListView view, int scrollState) { + state = scrollState; + } + + @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, + int totalItemCount) { + if (state == AbsListView.OnScrollListener.SCROLL_STATE_IDLE + && firstVisibleItem + visibleItemCount == totalItemCount) { + loadMore(); + } + } + }); + } + + private void loadMore() { + + } + + + +} diff --git a/Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java b/Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java new file mode 100644 index 00000000..e4c31183 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java @@ -0,0 +1,77 @@ +package com.arialyy.aria.window; + +import android.content.Context; +import android.util.SparseBooleanArray; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.CheckBox; +import android.widget.ImageView; +import android.widget.TextView; +import com.arialyy.aria.R; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Aria.Lao on 2017/3/21. + */ +final class FileChangeAdapter extends BaseAdapter { + + List mData = new ArrayList<>(); + SparseBooleanArray mCheck = new SparseBooleanArray(); + Context mContext; + + public FileChangeAdapter(Context context, List list) { + mContext = context; + mData.addAll(list); + for (int i = 0, len = mData.size(); i < len; i++) { + mCheck.append(i, false); + } + } + + @Override public int getCount() { + return mData.size(); + } + + @Override public Object getItem(int position) { + return null; + } + + @Override public long getItemId(int position) { + return 0; + } + + @Override public View getView(int position, View convertView, ViewGroup parent) { + FileChangeHolder holder = null; + if (convertView == null) { + convertView = LayoutInflater.from(mContext).inflate(R.layout.item_file, null); + holder = new FileChangeHolder(convertView); + convertView.setTag(holder); + } else { + holder = (FileChangeHolder) convertView.getTag(); + } + + holder.checkBox.setChecked(mCheck.get(position, false)); + return convertView; + } + + public void setCheck(int position, boolean check) { + if (position >= mData.size()) return; + mCheck.put(position, check); + notifyDataSetChanged(); + } + + private static class FileChangeHolder { + TextView title, info; + ImageView icon; + CheckBox checkBox; + + FileChangeHolder(View view) { + title = (TextView) view.findViewById(R.id.title); + info = (TextView) view.findViewById(R.id.info); + icon = (ImageView) view.findViewById(R.id.icon); + checkBox = (CheckBox) view.findViewById(R.id.checkbox); + } + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/window/FileEntity.java b/Aria/src/main/java/com/arialyy/aria/window/FileEntity.java new file mode 100644 index 00000000..e51481e4 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/window/FileEntity.java @@ -0,0 +1,14 @@ +package com.arialyy.aria.window; + +import android.graphics.drawable.Drawable; + +/** + * Created by Aria.Lao on 2017/3/21. + */ + +public class FileEntity { + public String fileName; + public String fileInfo; + public int fileIcon; + public Drawable fileDrawable; +} diff --git a/Aria/src/main/res/layout/activity_aria_file_shange.xml b/Aria/src/main/res/layout/activity_aria_file_shange.xml new file mode 100644 index 00000000..fd652062 --- /dev/null +++ b/Aria/src/main/res/layout/activity_aria_file_shange.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/Aria/src/main/res/layout/item_file.xml b/Aria/src/main/res/layout/item_file.xml new file mode 100644 index 00000000..7f4c8044 --- /dev/null +++ b/Aria/src/main/res/layout/item_file.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Aria/src/main/res/values/strings.xml b/Aria/src/main/res/values/strings.xml index fe69410b..010e9981 100644 --- a/Aria/src/main/res/values/strings.xml +++ b/Aria/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ - DownloadUtil + Aria 下载实体不能为空 下载链接不能为空