Merge branch 'v_3.0' of https://github.com/AriaLyy/Aria into v_3.0

pull/330/head
AriaLyy 8 years ago
commit 76b9987f46
  1. 2
      .idea/modules.xml
  2. 103
      Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
  3. 55
      Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java
  4. 77
      Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java
  5. 14
      Aria/src/main/java/com/arialyy/aria/window/FileEntity.java
  6. 14
      Aria/src/main/res/layout/activity_aria_file_shange.xml
  7. 51
      Aria/src/main/res/layout/item_file.xml
  8. 2
      Aria/src/main/res/values/strings.xml

@ -2,8 +2,10 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>

@ -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<FileEntity> loadFiles(String path) {
File file = new File(path);
File[] files = file.listFiles();
List<FileEntity> 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;
}
}
}

@ -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<String, List<FileEntity>> 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() {
}
}

@ -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<FileEntity> mData = new ArrayList<>();
SparseBooleanArray mCheck = new SparseBooleanArray();
Context mContext;
public FileChangeAdapter(Context context, List<FileEntity> 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);
}
}
}

@ -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;
}

@ -0,0 +1,14 @@
<?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"
>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false"
/>
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/img"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/checkbox"
android:layout_toRightOf="@+id/img"
android:ellipsize="end"
android:maxLines="1"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/title"
android:layout_below="@+id/title"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/checkbox"
/>
</RelativeLayout>

@ -1,5 +1,5 @@
<resources>
<string name="app_name">DownloadUtil</string>
<string name="app_name">Aria</string>
<string name="error_entity_null">下载实体不能为空</string>
<string name="error_download_url_null">下载链接不能为空</string>

Loading…
Cancel
Save