├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── gif
│ └── device-2017-11-10-105244.gif
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── choose
│ │ └── lm
│ │ └── com
│ │ └── choosefile
│ │ └── MainActivity.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── fileselector
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── choose
│ │ └── lm
│ │ └── com
│ │ └── fileselector
│ │ ├── activitys
│ │ └── ChooseFileActivity.java
│ │ ├── adapters
│ │ └── selectrecycleview
│ │ │ ├── ChoosePhotoAdapter.java
│ │ │ ├── SectionedRecyclerViewAdapter.java
│ │ │ └── SectionedSpanSizeLookup.java
│ │ ├── base
│ │ ├── BaseActivity.java
│ │ ├── BaseFragment.java
│ │ ├── MyApplication.java
│ │ ├── abslistview
│ │ │ ├── CommonAdapter.java
│ │ │ ├── MultiItemTypeAdapter.java
│ │ │ ├── ViewHolder.java
│ │ │ └── base
│ │ │ │ ├── ItemViewDelegate.java
│ │ │ │ └── ItemViewDelegateManager.java
│ │ └── recyclerview
│ │ │ ├── CommonAdapter.java
│ │ │ ├── MultiItemTypeAdapter.java
│ │ │ ├── base
│ │ │ ├── ItemViewDelegate.java
│ │ │ ├── ItemViewDelegateManager.java
│ │ │ └── ViewHolder.java
│ │ │ ├── utils
│ │ │ └── WrapperUtils.java
│ │ │ └── wrapper
│ │ │ ├── EmptyWrapper.java
│ │ │ ├── HeaderAndFooterWrapper.java
│ │ │ └── LoadmoreWrapper.java
│ │ ├── fragments
│ │ ├── FileFragment.java
│ │ ├── OtherFragment.java
│ │ ├── PhotoFragment.java
│ │ └── VideoFragment.java
│ │ ├── model
│ │ ├── FileGroupInfo.java
│ │ └── FileInfo.java
│ │ ├── utils
│ │ ├── DateUtil.java
│ │ ├── FileUtil.java
│ │ └── LoadFiles.java
│ │ └── widget
│ │ └── CustomTitleBar.java
│ └── res
│ ├── drawable-xhdpi
│ ├── ico_excel.png
│ ├── ico_mp3.png
│ ├── ico_other.png
│ ├── ico_pdf.png
│ ├── ico_pic.png
│ ├── ico_ppt.png
│ ├── ico_rar.png
│ ├── ico_sort_arrow_up.png
│ ├── ico_staff_checked.png
│ ├── ico_staff_unchecked.png
│ ├── ico_txt.png
│ ├── ico_video.png
│ ├── ico_wj_jt.png
│ ├── ico_wj_jt_on.png
│ ├── ico_word.png
│ ├── im_icon_camera.png
│ ├── im_icon_images.png
│ └── img_preloading.png
│ ├── drawable
│ ├── choose_file_up_down.xml
│ ├── lib_choose_file_send.xml
│ ├── lib_sl_single_choice.xml
│ └── nav_ico_left.png
│ ├── layout
│ ├── lib_activity_choose_file.xml
│ ├── lib_base_titlebar_layout.xml
│ ├── lib_item_file_group.xml
│ ├── lib_item_image_group.xml
│ ├── lib_item_photo_fragment.xml
│ ├── lib_item_video_fragment.xml
│ ├── lib_photo_fragment.xml
│ └── lib_video_fragment.xml
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ChooseFile
2 | 高仿QQ文件选择器,支持单选和多选
3 |
4 |
5 | 
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "27.0.0"
6 | defaultConfig {
7 | applicationId "choose.lm.com.choosefile"
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | dataBinding{
21 | enabled true
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:25.3.1'
31 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
32 | testCompile 'junit:junit:4.12'
33 | compile project(':fileselector')
34 | }
35 |
--------------------------------------------------------------------------------
/app/gif/device-2017-11-10-105244.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/gif/device-2017-11-10-105244.gif
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/choose/lm/com/choosefile/MainActivity.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.choosefile;
2 |
3 | import android.content.Intent;
4 | import android.view.View;
5 |
6 | import java.util.ArrayList;
7 |
8 | import choose.lm.com.choosefile.databinding.ActivityMainBinding;
9 | import choose.lm.com.fileselector.activitys.ChooseFileActivity;
10 | import choose.lm.com.fileselector.base.BaseActivity;
11 | import choose.lm.com.fileselector.model.FileInfo;
12 |
13 | public class MainActivity extends BaseActivity {
14 |
15 |
16 | @Override
17 | protected int getLayoutId() {
18 | return R.layout.activity_main;
19 | }
20 |
21 | @Override
22 | protected void initData() {
23 | super.initData();
24 | mBinding.btnStart.setOnClickListener(new View.OnClickListener() {
25 | @Override
26 | public void onClick(View v) {
27 | //发送文件
28 | Intent intent = ChooseFileActivity.newIntent(aty, true);//第二个参数为是否多选
29 | startActivityForResult(intent, 1);
30 | }
31 | });
32 |
33 | }
34 |
35 | @Override
36 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
37 | super.onActivityResult(requestCode, resultCode, data);
38 |
39 | if (data != null) {
40 | ArrayList list = data.getParcelableArrayListExtra(ChooseFileActivity.FILELISTDATA);
41 |
42 | StringBuilder str = new StringBuilder();
43 | for (int i = 0; i < list.size(); i++) {
44 | FileInfo fileInfo = list.get(i);
45 | str.append(fileInfo.getFile_path() + "\n");
46 | }
47 | mBinding.tvShow.setText(str.toString());
48 |
49 |
50 | }
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
15 |
16 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #15AAFF
4 | #15AAFF
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ChooseFile
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/fileselector/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fileselector/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "27.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | dataBinding{
23 | enabled true
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | compile 'com.android.support:appcompat-v7:25.3.1'
33 | compile 'com.android.support:design:25.3.1'
34 | compile 'com.android.support:recyclerview-v7:25.3.1'
35 | compile 'com.github.bumptech.glide:glide:3.7.0'
36 | testCompile 'junit:junit:4.12'
37 | }
38 |
--------------------------------------------------------------------------------
/fileselector/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/fileselector/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/activitys/ChooseFileActivity.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.activitys;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.Environment;
7 | import android.os.Parcelable;
8 | import android.support.design.widget.TabLayout;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v4.app.FragmentManager;
11 | import android.support.v4.app.FragmentPagerAdapter;
12 | import android.util.Log;
13 | import android.util.TypedValue;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 |
17 | import java.io.File;
18 | import java.io.IOError;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import choose.lm.com.fileselector.R;
23 | import choose.lm.com.fileselector.base.BaseActivity;
24 | import choose.lm.com.fileselector.databinding.LibActivityChooseFileBinding;
25 | import choose.lm.com.fileselector.fragments.FileFragment;
26 | import choose.lm.com.fileselector.fragments.OtherFragment;
27 | import choose.lm.com.fileselector.fragments.PhotoFragment;
28 | import choose.lm.com.fileselector.fragments.VideoFragment;
29 | import choose.lm.com.fileselector.model.FileInfo;
30 | import choose.lm.com.fileselector.utils.FileUtil;
31 | import choose.lm.com.fileselector.utils.LoadFiles;
32 | import choose.lm.com.fileselector.widget.CustomTitleBar;
33 |
34 | public class ChooseFileActivity extends BaseActivity {
35 | public static String FILELISTDATA = "file_data_list";
36 |
37 |
38 | private List mSelectFiles = new ArrayList<>();
39 | private List mFragmentList = new ArrayList<>();
40 | private List title = new ArrayList<>();
41 | private MyPagerAdapter adapter;
42 | private VideoFragment videoFragment;
43 | private PhotoFragment photoFragment;
44 | private FileFragment fileFragment;
45 | private OtherFragment otherFragment;
46 | /**
47 | * 是否允许多选
48 | */
49 | private static final String EXTRA_IS_MULTI_SELECT = "EXTRA_IS_MULTI_SELECT";
50 | public boolean mIsMultiselect = false;
51 | private int mCurPosition = 0;
52 |
53 | @Override
54 | public int getLayoutId() {
55 | return R.layout.lib_activity_choose_file;
56 | }
57 |
58 | /**
59 | * 选择文件的intent
60 | *
61 | * @param context Context
62 | * @param isMultiselect 是否允许多选
63 | * @return
64 | */
65 | public static Intent newIntent(Context context, boolean isMultiselect) {
66 | Intent intent = new Intent(context, ChooseFileActivity.class);
67 | intent.putExtra(EXTRA_IS_MULTI_SELECT, isMultiselect);
68 | return intent;
69 |
70 | }
71 |
72 | @Override
73 | protected void initTitle() {
74 | super.initTitle();
75 | mBinding.ctbTitle.setTitle("选择文件");
76 | mBinding.ctbTitle.setOnBackClickListener(new CustomTitleBar.IBackClickListener() {
77 | @Override
78 | public void OnBackClick() {
79 | finish();
80 | }
81 | });
82 | mBinding.tvSend.setOnClickListener(new View.OnClickListener() {
83 | @Override
84 | public void onClick(View v) {
85 | setResult(RESULT_OK, new Intent().putParcelableArrayListExtra(FILELISTDATA, (ArrayList extends Parcelable>) mSelectFiles));
86 | finish();
87 | }
88 | });
89 | }
90 |
91 | @Override
92 | public void initData() {
93 | super.initData();
94 |
95 |
96 |
97 | mIsMultiselect = getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECT, false);
98 | title.add("影音");
99 | title.add("图片");
100 | title.add("文档");
101 | title.add("其他");
102 | videoFragment = new VideoFragment();
103 | photoFragment = new PhotoFragment();
104 | fileFragment = new FileFragment();
105 | otherFragment = new OtherFragment();
106 | mFragmentList.add(videoFragment);
107 | mFragmentList.add(photoFragment);
108 | mFragmentList.add(fileFragment);
109 | mFragmentList.add(otherFragment);
110 |
111 | if (mIsMultiselect) {//多选
112 | mBinding.tvSend.setText("发送(0)");
113 | } else {
114 | mBinding.tvSend.setText("发送");
115 | }
116 |
117 |
118 | }
119 |
120 | String ACTION_MEDIA_SCANNER_SCAN_DIR = "android.intent.action.MEDIA_SCANNER_SCAN_DIR";
121 |
122 | @Override
123 | protected void initView(Bundle savedInstanceState) {
124 | super.initView(savedInstanceState);
125 | /*
126 | Intent scanIntent = new Intent(ACTION_MEDIA_SCANNER_SCAN_DIR);
127 | scanIntent.setData(Uri.parse("file://" + Environment.getExternalStorageDirectory()));
128 | sendBroadcast(scanIntent);*/
129 | //刷新文件
130 | // sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
131 | // sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
132 | adapter = new MyPagerAdapter(getSupportFragmentManager());
133 | mBinding.vpChooseFile.setAdapter(adapter);
134 | final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
135 | .getDisplayMetrics());
136 | mBinding.vpChooseFile.setPageMargin(pageMargin);
137 |
138 | mBinding.tabLayout.setupWithViewPager(mBinding.vpChooseFile);
139 | mBinding.vpChooseFile.setOffscreenPageLimit(4);
140 | mBinding.vpChooseFile.setCurrentItem(0);
141 | mBinding.tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
142 | @Override
143 | public void onTabSelected(TabLayout.Tab tab) {
144 | mCurPosition = tab.getPosition();
145 | }
146 |
147 | @Override
148 | public void onTabUnselected(TabLayout.Tab tab) {
149 |
150 | }
151 |
152 | @Override
153 | public void onTabReselected(TabLayout.Tab tab) {
154 |
155 | }
156 | });
157 |
158 |
159 | new Thread(){
160 | @Override
161 | public void run() {
162 | super.run();
163 | try {
164 | int qq = findFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Tencent/QQfile_recv");
165 | int weixin_img = findFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Tencent/MicroMsg/Download");
166 | int weixin_file = findFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Tencent/MicroMsg/WeiXin");
167 | if (qq+weixin_img+weixin_file>0) {//扫描qq和微信的文件
168 | updateData();
169 | }
170 | } catch (IOError e) {
171 | Log.e("fileName", "出错了");
172 | e.printStackTrace();
173 | }
174 | }
175 | }.start();
176 | }
177 |
178 |
179 | private void updateData()
180 | {
181 | videoFragment.loadData();
182 | photoFragment.loadData();
183 | fileFragment.loadData();
184 | otherFragment.loadData();
185 | }
186 |
187 | private int findFile(String PathName) {
188 |
189 | String fileName[] = (new File(PathName)).list();
190 | if(fileName == null)
191 | {
192 | return 0;
193 | }
194 | File fileTemp;
195 |
196 | for (int j = 0; j < fileName.length; j++) {
197 |
198 | fileTemp = new File(PathName + '/' + fileName[j]);
199 | Log.e("fileName", fileName[j]);
200 | if (fileTemp.isFile()) {
201 | LoadFiles.insertFile(getContentResolver(),fileTemp);
202 | } else if (fileTemp.isDirectory()) {
203 | findFile(PathName + '/' + fileName[j]);
204 | }
205 | }
206 | return 1;
207 | }
208 |
209 | public void addFile(FileInfo fileInfo) {
210 | mSelectFiles.add(fileInfo);
211 | refershView();
212 | }
213 |
214 | //单选默认 清楚其他页面的状态和数据
215 | public void clearFile() {
216 | mSelectFiles.clear();
217 | switch (mCurPosition) {
218 | case 0:
219 | photoFragment.clearState();
220 | fileFragment.clearState();
221 | otherFragment.clearState();
222 | break;
223 | case 1:
224 | videoFragment.clearState();
225 | fileFragment.clearState();
226 | otherFragment.clearState();
227 | break;
228 | case 2:
229 | videoFragment.clearState();
230 | photoFragment.clearState();
231 | otherFragment.clearState();
232 | break;
233 | case 3:
234 | videoFragment.clearState();
235 | photoFragment.clearState();
236 | fileFragment.clearState();
237 | break;
238 | }
239 |
240 |
241 | }
242 |
243 | public void removeFile(int id) {
244 | for (int i = 0; i < mSelectFiles.size(); i++) {
245 | if (id == mSelectFiles.get(i).getId()) {
246 | mSelectFiles.remove(i);
247 | }
248 | }
249 | refershView();
250 | }
251 |
252 | private void refershView() {
253 | int count = 0;
254 | long size = 0;
255 | for (int i = 0; i < mSelectFiles.size(); i++) {
256 | size = size + mSelectFiles.get(i).getFile_size();
257 | count++;
258 | }
259 | mBinding.idChooseSize.setText("已选" + FileUtil.bytes2kb(size));
260 | if (count > 0) {
261 | mBinding.tvSend.setSelected(true);
262 | mBinding.tvSend.setTextColor(getResources().getColor(R.color.colorFFFFFF));
263 | } else {
264 | mBinding.tvSend.setSelected(false);
265 | mBinding.tvSend.setTextColor(getResources().getColor(R.color.colorC9C9C9));
266 | }
267 | if (mIsMultiselect) {//多选
268 | mBinding.tvSend.setText("发送(" + count + ")");
269 | } else {
270 | mBinding.tvSend.setText("发送");
271 | }
272 |
273 | }
274 |
275 |
276 |
277 | class MyPagerAdapter extends FragmentPagerAdapter {
278 |
279 | public MyPagerAdapter(FragmentManager fm) {
280 | super(fm);
281 | }
282 |
283 | @Override
284 | public CharSequence getPageTitle(int position) {
285 | return title.get(position);
286 | }
287 |
288 | @Override
289 | public int getCount() {
290 | return title.size();
291 | }
292 |
293 | @Override
294 | public Fragment getItem(int position) {
295 | return mFragmentList.get(position);
296 | }
297 |
298 | @Override
299 | public Object instantiateItem(ViewGroup container, int position) {
300 | Object obj = super.instantiateItem(container, position);
301 | return obj;
302 | }
303 |
304 | @Override
305 | public void destroyItem(ViewGroup container, int position, Object object) {
306 | super.destroyItem(container, position, object);
307 | }
308 | }
309 | }
310 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/adapters/selectrecycleview/ChoosePhotoAdapter.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.adapters.selectrecycleview;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.text.TextUtils;
7 | import android.util.SparseBooleanArray;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.FrameLayout;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 | import android.widget.RelativeLayout;
15 | import android.widget.TextView;
16 |
17 | import com.bumptech.glide.Glide;
18 | import com.bumptech.glide.RequestManager;
19 |
20 | import java.io.File;
21 | import java.util.ArrayList;
22 | import java.util.HashMap;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | import choose.lm.com.fileselector.R;
27 | import choose.lm.com.fileselector.model.FileGroupInfo;
28 | import choose.lm.com.fileselector.model.FileInfo;
29 |
30 | /**
31 | * Created by Administrator on 2016/12/9 0009.
32 | */
33 | public class ChoosePhotoAdapter extends SectionedRecyclerViewAdapter {
34 |
35 | public List mDataList = new ArrayList<>();
36 | private Context mContext;
37 | private LayoutInflater mInflater;
38 | private Map map1;
39 | private SparseBooleanArray mBooleanMap;
40 | private int group = -1, child = -1, position11 = -1;
41 | private boolean mIsMultiselect=false;
42 | private RequestManager mRequestManager;
43 | public ChoosePhotoAdapter(Context context,boolean isMultiselect) {
44 | mContext = context;
45 | mInflater = LayoutInflater.from(context);
46 | mBooleanMap = new SparseBooleanArray();
47 | map1 = new HashMap<>();
48 | mIsMultiselect=isMultiselect;
49 | mRequestManager = Glide.with(mContext);
50 | mRequestManager.onLowMemory();
51 | width = ((Activity)mContext).getWindowManager().getDefaultDisplay().getWidth();
52 | }
53 |
54 | int width = 0;
55 |
56 | public void setData(List dataList) {
57 | mDataList = dataList;
58 | for (int i = 0; i < dataList.size(); i++) {
59 | map1.put(i, new SparseBooleanArray());
60 | }
61 | notifyDataSetChanged();
62 |
63 | }
64 |
65 | public List getDataList() {
66 | return mDataList;
67 | }
68 | public void clearState()
69 | {
70 | for (int i = 0; i < mDataList.size(); i++) {
71 | map1.put(i, new SparseBooleanArray());
72 | }
73 | notifyDataSetChanged();
74 | }
75 |
76 | @Override
77 | protected int getSectionCount() {
78 | return mDataList.size();
79 | }
80 |
81 | @Override
82 | protected int getItemCountForSection(int section) {
83 | /* int count = allTagList.get(section).tagInfoList.size();
84 | if (count >= 8 && !mBooleanMap.get(section)) {
85 | count = 8;
86 | }
87 |
88 | return HotelUtils.isEmpty(allTagList.get(section).tagInfoList) ? 0 : count;*/
89 | boolean b = mBooleanMap.get(section);
90 |
91 | return !mBooleanMap.get(section) ? 0 : mDataList.get(section).getmFileList().size();
92 | }
93 |
94 | //是否有footer布局
95 | @Override
96 | protected boolean hasFooterInSection(int section) {
97 | return false;
98 | }
99 |
100 | @Override
101 | protected GroupHolder onCreateSectionHeaderViewHolder(ViewGroup parent, int viewType) {
102 | return new GroupHolder(mInflater.inflate(R.layout.lib_item_image_group, parent, false));
103 | }
104 |
105 |
106 | @Override
107 | protected RecyclerView.ViewHolder onCreateSectionFooterViewHolder(ViewGroup parent, int viewType) {
108 | return null;
109 | }
110 |
111 | @Override
112 | protected ChildHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
113 | View inflate = mInflater.inflate(R.layout.lib_item_photo_fragment, parent, false);
114 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width / 4, width / 4);
115 | inflate.setLayoutParams(layoutParams);
116 | return new ChildHolder(inflate);
117 | }
118 |
119 |
120 | @Override
121 | protected void onBindSectionHeaderViewHolder(final GroupHolder holder, final int section) {
122 |
123 | final boolean b = mBooleanMap.get(section);
124 | if (b) {
125 | holder.img_choose.setSelected(true);
126 | } else {
127 | holder.img_choose.setSelected(false);
128 | }
129 | holder.tv_group_name.setText(mDataList.get(section).getGroup_name());
130 | holder.lly_group.setOnClickListener(new View.OnClickListener() {
131 | @Override
132 | public void onClick(View v) {
133 | mBooleanMap.put(section, !b);
134 | if (mOnItemClickListener != null) {
135 | mOnItemClickListener.onGroupClick(section);
136 | }
137 | notifyDataSetChanged();
138 |
139 | }
140 | });
141 | }
142 | @Override
143 | protected void onBindSectionFooterViewHolder(RecyclerView.ViewHolder holder, int section) {
144 |
145 | }
146 |
147 | @Override
148 | protected void onBindItemViewHolder(ChildHolder holder, final int section, final int position, final int position1) {
149 | FileInfo fileInfo = mDataList.get(section).getmFileList().get(position);
150 | if (!TextUtils.isEmpty(fileInfo.getFile_path()) && fileInfo.getFile_path().contains(".gif")) {
151 | mRequestManager.load(new File(fileInfo.getFile_path())).asBitmap().thumbnail(0.7f).placeholder(R.drawable.img_preloading).into(holder.img);
152 |
153 | } else {
154 | mRequestManager.load(new File(fileInfo.getFile_path())).thumbnail(0.7f).placeholder(R.drawable.img_preloading).into(holder.img);
155 | }
156 |
157 | final SparseBooleanArray sparseBooleanArray = map1.get(section);
158 | if (sparseBooleanArray.get(position)) {
159 | holder.imgV_select.setSelected(true);
160 | holder.rl_choose.setVisibility(View.VISIBLE);
161 | } else {
162 | holder.imgV_select.setSelected(false);
163 | holder.rl_choose.setVisibility(View.GONE);
164 | }
165 |
166 | holder.fl_item.setOnClickListener(new View.OnClickListener() {
167 | @Override
168 | public void onClick(View v) {
169 | if (mOnItemClickListener != null) {
170 | mOnItemClickListener.onChildClick(section, position,!sparseBooleanArray.get(position));
171 |
172 | SparseBooleanArray sparseBooleanArray = map1.get(section);
173 | if (sparseBooleanArray.get(position)) {
174 | sparseBooleanArray.put(position, false);
175 | } else {
176 | sparseBooleanArray.put(position, true);
177 | }
178 | map1.put(section, sparseBooleanArray);
179 | if (!mIsMultiselect) {//单选模式
180 | if (group != -1 && !(group == section && child == position)) {
181 | map1.get(group).put(child, false);
182 | notifyItemChanged(position11);
183 | }
184 |
185 | group = section;
186 | child = position;
187 | position11 = position1;
188 | }
189 |
190 |
191 | notifyItemChanged(position1);
192 | }
193 | }
194 | });
195 | }
196 |
197 | public class GroupHolder extends RecyclerView.ViewHolder {
198 | public ImageView img_choose;
199 | public TextView tv_group_name;
200 | public LinearLayout lly_group;
201 | public GroupHolder(View itemView) {
202 | super(itemView);
203 | img_choose= (ImageView) itemView.findViewById(R.id.img_choose);
204 | tv_group_name= (TextView) itemView.findViewById(R.id.tv_group_name);
205 | lly_group= (LinearLayout) itemView.findViewById(R.id.lly_group);
206 | }
207 | }
208 |
209 | public class ChildHolder extends RecyclerView.ViewHolder {
210 | public RelativeLayout rl_choose;
211 | public ImageView imgV_select;
212 | public ImageView img;
213 | public FrameLayout fl_item;
214 | public ChildHolder(View itemView) {
215 | super(itemView);
216 | rl_choose= (RelativeLayout) itemView.findViewById(R.id.rl_choose);
217 | imgV_select= (ImageView) itemView.findViewById(R.id.imgV_select);
218 | img= (ImageView) itemView.findViewById(R.id.img);
219 | fl_item= (FrameLayout) itemView.findViewById(R.id.fl_item);
220 | }
221 | }
222 |
223 | private onItemClickListener mOnItemClickListener;
224 |
225 | public void setOnItemClickListener(onItemClickListener onItemClickListener) {
226 | mOnItemClickListener = onItemClickListener;
227 | }
228 |
229 | public interface onItemClickListener {
230 | void onGroupClick(int group);
231 |
232 | void onChildClick(int group, int child,boolean is_choose);
233 | }
234 | }
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/adapters/selectrecycleview/SectionedRecyclerViewAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Tomás Ruiz-López.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package choose.lm.com.fileselector.adapters.selectrecycleview;
17 |
18 | import android.support.v7.widget.RecyclerView;
19 | import android.view.ViewGroup;
20 |
21 | /**
22 | * An extension to RecyclerView.Adapter to provide sections with headers and footers to a
23 | * RecyclerView. Each section can have an arbitrary number of items.
24 | *
25 | * @param Class extending RecyclerView.ViewHolder to hold and bind the header view
26 | * @param Class extending RecyclerView.ViewHolder to hold and bind the items view
27 | * @param Class extending RecyclerView.ViewHolder to hold and bind the footer view
28 | */
29 | public abstract class SectionedRecyclerViewAdapter
32 | extends RecyclerView.Adapter {
33 |
34 | protected static final int TYPE_SECTION_HEADER = -1;
35 | protected static final int TYPE_SECTION_FOOTER = -2;
36 | protected static final int TYPE_ITEM = -3;
37 |
38 | private int[] sectionForPosition = null;
39 | private int[] positionWithinSection = null;
40 | private boolean[] isHeader = null;
41 | private boolean[] isFooter = null;
42 | private int count = 0;
43 |
44 | public SectionedRecyclerViewAdapter() {
45 | super();
46 | registerAdapterDataObserver(new SectionDataObserver());
47 | }
48 |
49 | @Override
50 | public void onAttachedToRecyclerView(RecyclerView recyclerView) {
51 | super.onAttachedToRecyclerView(recyclerView);
52 | setupIndices();
53 | }
54 |
55 | /**
56 | * Returns the sum of number of items for each section plus headers and footers if they
57 | * are provided.
58 | */
59 | @Override
60 | public int getItemCount() {
61 | return count;
62 | }
63 |
64 | private void setupIndices(){
65 | count = countItems();
66 | allocateAuxiliaryArrays(count);
67 | precomputeIndices();
68 | }
69 |
70 | private int countItems() {
71 | int count = 0;
72 | int sections = getSectionCount();
73 |
74 | for(int i = 0; i < sections; i++){
75 | count += 1 + getItemCountForSection(i) + (hasFooterInSection(i) ? 1 : 0);
76 | }
77 | return count;
78 | }
79 |
80 | private void precomputeIndices(){
81 | int sections = getSectionCount();
82 | int index = 0;
83 |
84 | for(int i = 0; i < sections; i++){
85 | setPrecomputedItem(index, true, false, i, 0);
86 | index++;
87 |
88 | for(int j = 0; j < getItemCountForSection(i); j++){
89 | setPrecomputedItem(index, false, false, i, j);
90 | index++;
91 | }
92 |
93 | if(hasFooterInSection(i)){
94 | setPrecomputedItem(index, false, true, i, 0);
95 | index++;
96 | }
97 | }
98 | }
99 |
100 | private void allocateAuxiliaryArrays(int count) {
101 | sectionForPosition = new int[count];
102 | positionWithinSection = new int[count];
103 | isHeader = new boolean[count];
104 | isFooter = new boolean[count];
105 | }
106 |
107 | private void setPrecomputedItem(int index, boolean isHeader, boolean isFooter, int section, int position) {
108 | this.isHeader[index] = isHeader;
109 | this.isFooter[index] = isFooter;
110 | sectionForPosition[index] = section;
111 | positionWithinSection[index] = position;
112 | }
113 |
114 | @Override
115 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
116 | RecyclerView.ViewHolder viewHolder;
117 |
118 | if(isSectionHeaderViewType(viewType)){
119 | viewHolder = onCreateSectionHeaderViewHolder(parent, viewType);
120 | }else if(isSectionFooterViewType(viewType)){
121 | viewHolder = onCreateSectionFooterViewHolder(parent, viewType);
122 | }else{
123 | viewHolder = onCreateItemViewHolder(parent, viewType);
124 | }
125 |
126 | return viewHolder;
127 | }
128 |
129 | @Override
130 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
131 | int section = sectionForPosition[position];
132 | int index = positionWithinSection[position];
133 |
134 | if(isSectionHeaderPosition(position)){
135 | onBindSectionHeaderViewHolder((H) holder, section);
136 | }else if(isSectionFooterPosition(position)){
137 | onBindSectionFooterViewHolder((F) holder, section);
138 | }else{
139 | onBindItemViewHolder((VH) holder, section, index,position);
140 | }
141 |
142 | }
143 |
144 | @Override
145 | public int getItemViewType(int position) {
146 |
147 | if(sectionForPosition == null){
148 | setupIndices();
149 | }
150 |
151 | int section = sectionForPosition[position];
152 | int index = positionWithinSection[position];
153 |
154 | if(isSectionHeaderPosition(position)){
155 | return getSectionHeaderViewType(section);
156 | }else if(isSectionFooterPosition(position)){
157 | return getSectionFooterViewType(section);
158 | }else{
159 | return getSectionItemViewType(section, index);
160 | }
161 |
162 | }
163 |
164 | protected int getSectionHeaderViewType(int section){
165 | return TYPE_SECTION_HEADER;
166 | }
167 |
168 | protected int getSectionFooterViewType(int section){
169 | return TYPE_SECTION_FOOTER;
170 | }
171 |
172 | protected int getSectionItemViewType(int section, int position){
173 | return TYPE_ITEM;
174 | }
175 |
176 | /**
177 | * Returns true if the argument position corresponds to a header
178 | */
179 | public boolean isSectionHeaderPosition(int position){
180 | if(isHeader == null){
181 | setupIndices();
182 | }
183 | return isHeader[position];
184 | }
185 |
186 | /**
187 | * Returns true if the argument position corresponds to a footer
188 | */
189 | public boolean isSectionFooterPosition(int position){
190 | if(isFooter == null){
191 | setupIndices();
192 | }
193 | return isFooter[position];
194 | }
195 |
196 | protected boolean isSectionHeaderViewType(int viewType){
197 | return viewType == TYPE_SECTION_HEADER;
198 | }
199 |
200 | protected boolean isSectionFooterViewType(int viewType){
201 | return viewType == TYPE_SECTION_FOOTER;
202 | }
203 |
204 | /**
205 | * Returns the number of sections in the RecyclerView
206 | */
207 | protected abstract int getSectionCount();
208 |
209 | /**
210 | * Returns the number of items for a given section
211 | */
212 | protected abstract int getItemCountForSection(int section);
213 |
214 | /**
215 | * Returns true if a given section should have a footer
216 | */
217 | protected abstract boolean hasFooterInSection(int section);
218 |
219 | /**
220 | * Creates a ViewHolder of class H for a Header
221 | */
222 | protected abstract H onCreateSectionHeaderViewHolder(ViewGroup parent, int viewType);
223 |
224 | /**
225 | * Creates a ViewHolder of class F for a Footer
226 | */
227 | protected abstract F onCreateSectionFooterViewHolder(ViewGroup parent, int viewType);
228 |
229 | /**
230 | * Creates a ViewHolder of class VH for an Item
231 | */
232 | protected abstract VH onCreateItemViewHolder(ViewGroup parent, int viewType);
233 |
234 | /**
235 | * Binds data to the header view of a given section
236 | */
237 | protected abstract void onBindSectionHeaderViewHolder(H holder, int section);
238 |
239 | /**
240 | * Binds data to the footer view of a given section
241 | */
242 | protected abstract void onBindSectionFooterViewHolder(F holder, int section);
243 |
244 | /**
245 | * Binds data to the item view for a given position within a section
246 | */
247 | protected abstract void onBindItemViewHolder(VH holder, int section, int position, int position1);
248 |
249 | class SectionDataObserver extends RecyclerView.AdapterDataObserver{
250 | @Override
251 | public void onChanged() {
252 | setupIndices();
253 | }
254 | }
255 |
256 | public int getItemPosition(int position) {
257 | return positionWithinSection[position];
258 | }
259 | }
260 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/adapters/selectrecycleview/SectionedSpanSizeLookup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Tomás Ruiz-López.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package choose.lm.com.fileselector.adapters.selectrecycleview;
17 |
18 | import android.support.v7.widget.GridLayoutManager;
19 |
20 |
21 | /**
22 | * A SpanSizeLookup to draw section headers or footer spanning the whole width of the RecyclerView
23 | * when using a GridLayoutManager
24 | */
25 | public class SectionedSpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
26 |
27 | protected SectionedRecyclerViewAdapter, ?, ?> adapter = null;
28 | protected GridLayoutManager layoutManager = null;
29 |
30 | public SectionedSpanSizeLookup(SectionedRecyclerViewAdapter, ?, ?> adapter, GridLayoutManager layoutManager) {
31 | this.adapter = adapter;
32 | this.layoutManager = layoutManager;
33 | }
34 |
35 | @Override
36 | public int getSpanSize(int position) {
37 |
38 | if(adapter.isSectionHeaderPosition(position) || adapter.isSectionFooterPosition(position)){
39 | return layoutManager.getSpanCount();
40 | }else{
41 | return 1;
42 | }
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base;
2 |
3 | import android.app.Activity;
4 | import android.databinding.DataBindingUtil;
5 | import android.databinding.ViewDataBinding;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.app.FragmentActivity;
9 |
10 | /**
11 | * Created by zk on 2017/6/1.
12 | * Description:
13 | */
14 |
15 | public abstract class BaseActivity extends FragmentActivity {
16 |
17 |
18 | protected B mBinding;
19 | protected Activity aty;
20 |
21 | @Override
22 | protected void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | aty = this;
25 | mBinding = DataBindingUtil.inflate(getLayoutInflater(), getLayoutId(), null, false);
26 | setContentView(mBinding.getRoot());
27 | initTitle();
28 | initData();
29 | initEvent();
30 | initView(savedInstanceState);
31 | }
32 |
33 | protected abstract int getLayoutId();
34 | protected void initTitle() {
35 |
36 | }
37 |
38 | protected void initEvent() {
39 |
40 | }
41 |
42 | protected void initView(Bundle savedInstanceState) {
43 |
44 | }
45 |
46 | protected void initData() {
47 |
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base;
2 |
3 | import android.app.Activity;
4 | import android.databinding.DataBindingUtil;
5 | import android.databinding.ViewDataBinding;
6 | import android.os.Bundle;
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | /**
13 | * Created by zk on 2017/6/1.
14 | * Description:
15 | */
16 |
17 | public abstract class BaseFragment< B extends ViewDataBinding> extends Fragment {
18 |
19 | /**
20 | * Fragment根视图
21 | */
22 | protected View mFragmentRootView;
23 |
24 | protected B mBinding;
25 | protected Activity aty;
26 |
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
30 | mFragmentRootView = inflaterView(inflater, container, savedInstanceState);
31 | aty = getActivity();
32 |
33 |
34 | initTitle();
35 | initData();
36 | initEvent();
37 | initView(savedInstanceState);
38 | return mFragmentRootView;
39 | }
40 |
41 |
42 | /**
43 | * 加载View
44 | *
45 | * @param inflater LayoutInflater
46 | * @param container ViewGroup
47 | * @param bundle Bundle
48 | * @return
49 | */
50 | protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
51 | mBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
52 | return mBinding.getRoot();
53 | }
54 | protected abstract int getLayoutId();
55 |
56 | protected void initTitle() {
57 |
58 | }
59 | protected void initEvent() {
60 |
61 | }
62 |
63 | protected void initView(Bundle savedInstanceState) {
64 |
65 | }
66 |
67 | protected void initData() {
68 |
69 | }
70 |
71 |
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/MyApplication.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base;
2 |
3 | import android.app.Application;
4 |
5 | /**
6 | * Created by Administrator on 2017/11/9 0009.
7 | */
8 |
9 | public class MyApplication extends Application {
10 | public static MyApplication myApplication;
11 |
12 | public static MyApplication getInstance() {
13 | return myApplication;
14 | }
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | myApplication = this;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/abslistview/CommonAdapter.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.abslistview;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.List;
6 |
7 | import choose.lm.com.fileselector.base.abslistview.base.ItemViewDelegate;
8 |
9 |
10 | public abstract class CommonAdapter extends MultiItemTypeAdapter
11 | {
12 |
13 | public CommonAdapter(Context context, final int layoutId, List datas)
14 | {
15 | super(context, datas);
16 |
17 | addItemViewDelegate(new ItemViewDelegate()
18 | {
19 | @Override
20 | public int getItemViewLayoutId()
21 | {
22 | return layoutId;
23 | }
24 |
25 | @Override
26 | public boolean isForViewType(T item, int position)
27 | {
28 | return true;
29 | }
30 |
31 | @Override
32 | public void convert(ViewHolder holder, T t, int position)
33 | {
34 | CommonAdapter.this.convert(holder, t, position);
35 | }
36 | });
37 | }
38 |
39 | protected abstract void convert(ViewHolder viewHolder, T item, int position);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/abslistview/MultiItemTypeAdapter.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.abslistview;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 |
9 | import java.util.List;
10 |
11 | import choose.lm.com.fileselector.base.abslistview.base.ItemViewDelegate;
12 | import choose.lm.com.fileselector.base.abslistview.base.ItemViewDelegateManager;
13 |
14 |
15 | public class MultiItemTypeAdapter extends BaseAdapter {
16 | protected Context mContext;
17 | protected List mDatas;
18 |
19 | private ItemViewDelegateManager mItemViewDelegateManager;
20 |
21 |
22 | public MultiItemTypeAdapter(Context context, List datas) {
23 | this.mContext = context;
24 | this.mDatas = datas;
25 | mItemViewDelegateManager = new ItemViewDelegateManager();
26 | }
27 |
28 | public MultiItemTypeAdapter addItemViewDelegate(ItemViewDelegate itemViewDelegate) {
29 | mItemViewDelegateManager.addDelegate(itemViewDelegate);
30 | return this;
31 | }
32 |
33 | private boolean useItemViewDelegateManager() {
34 | return mItemViewDelegateManager.getItemViewDelegateCount() > 0;
35 | }
36 |
37 | @Override
38 | public int getViewTypeCount() {
39 | if (useItemViewDelegateManager())
40 | return mItemViewDelegateManager.getItemViewDelegateCount();
41 | return super.getViewTypeCount();
42 | }
43 |
44 | @Override
45 | public int getItemViewType(int position) {
46 | if (useItemViewDelegateManager()) {
47 | int viewType = mItemViewDelegateManager.getItemViewType(mDatas.get(position), position);
48 | return viewType;
49 | }
50 | return super.getItemViewType(position);
51 | }
52 |
53 | @Override
54 | public View getView(int position, View convertView, ViewGroup parent) {
55 | ItemViewDelegate itemViewDelegate = mItemViewDelegateManager.getItemViewDelegate(mDatas.get(position), position);
56 | int layoutId = itemViewDelegate.getItemViewLayoutId();
57 | ViewHolder viewHolder = null ;
58 | if (convertView == null)
59 | {
60 | View itemView = LayoutInflater.from(mContext).inflate(layoutId, parent,
61 | false);
62 | viewHolder = new ViewHolder(mContext, itemView, parent, position);
63 | viewHolder.mLayoutId = layoutId;
64 | onViewHolderCreated(viewHolder,viewHolder.getConvertView());
65 | } else
66 | {
67 | viewHolder = (ViewHolder) convertView.getTag();
68 | viewHolder.mPosition = position;
69 | }
70 |
71 |
72 | convert(viewHolder, getItem(position), position);
73 | return viewHolder.getConvertView();
74 | }
75 |
76 | protected void convert(ViewHolder viewHolder, T item, int position) {
77 | mItemViewDelegateManager.convert(viewHolder, item, position);
78 | }
79 |
80 | public void onViewHolderCreated(ViewHolder holder , View itemView )
81 | {}
82 |
83 | @Override
84 | public int getCount() {
85 | return mDatas.size();
86 | }
87 |
88 | @Override
89 | public T getItem(int position) {
90 | return mDatas.get(position);
91 | }
92 |
93 | @Override
94 | public long getItemId(int position) {
95 | return position;
96 | }
97 |
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/abslistview/ViewHolder.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.abslistview;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Paint;
7 | import android.graphics.Typeface;
8 | import android.graphics.drawable.Drawable;
9 | import android.os.Build;
10 | import android.text.util.Linkify;
11 | import android.util.SparseArray;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.view.animation.AlphaAnimation;
16 | import android.widget.Checkable;
17 | import android.widget.ImageView;
18 | import android.widget.ProgressBar;
19 | import android.widget.RatingBar;
20 | import android.widget.TextView;
21 |
22 | public class ViewHolder
23 | {
24 | private SparseArray mViews;
25 | protected int mPosition;
26 | private View mConvertView;
27 | private Context mContext;
28 | protected int mLayoutId;
29 |
30 | public ViewHolder(Context context, View itemView, ViewGroup parent, int position)
31 | {
32 | mContext = context;
33 | mConvertView = itemView;
34 | mPosition = position;
35 | mViews = new SparseArray();
36 | mConvertView.setTag(this);
37 | }
38 |
39 |
40 | public static ViewHolder get(Context context, View convertView,
41 | ViewGroup parent, int layoutId, int position)
42 | {
43 | if (convertView == null)
44 | {
45 | View itemView = LayoutInflater.from(context).inflate(layoutId, parent,
46 | false);
47 | ViewHolder holder = new ViewHolder(context, itemView, parent, position);
48 | holder.mLayoutId = layoutId;
49 | return holder;
50 | } else
51 | {
52 | ViewHolder holder = (ViewHolder) convertView.getTag();
53 | holder.mPosition = position;
54 | return holder;
55 | }
56 | }
57 |
58 |
59 | /**
60 | * 通过viewId获取控件
61 | *
62 | * @param viewId
63 | * @return
64 | */
65 | public T getView(int viewId)
66 | {
67 | View view = mViews.get(viewId);
68 | if (view == null)
69 | {
70 | view = mConvertView.findViewById(viewId);
71 | mViews.put(viewId, view);
72 | }
73 | return (T) view;
74 | }
75 |
76 | public View getConvertView()
77 | {
78 | return mConvertView;
79 | }
80 |
81 | public int getLayoutId()
82 | {
83 | return mLayoutId;
84 | }
85 |
86 | public void updatePosition(int position)
87 | {
88 | mPosition = position;
89 | }
90 |
91 | public int getItemPosition()
92 | {
93 | return mPosition;
94 | }
95 |
96 |
97 | /****以下为辅助方法*****/
98 |
99 | /**
100 | * 设置TextView的值
101 | *
102 | * @param viewId
103 | * @param text
104 | * @return
105 | */
106 | public ViewHolder setText(int viewId, String text)
107 | {
108 | TextView tv = getView(viewId);
109 | tv.setText(text);
110 | return this;
111 | }
112 |
113 | public ViewHolder setImageResource(int viewId, int resId)
114 | {
115 | ImageView view = getView(viewId);
116 | view.setImageResource(resId);
117 | return this;
118 | }
119 |
120 | public ViewHolder setImageBitmap(int viewId, Bitmap bitmap)
121 | {
122 | ImageView view = getView(viewId);
123 | view.setImageBitmap(bitmap);
124 | return this;
125 | }
126 |
127 | public ViewHolder setImageDrawable(int viewId, Drawable drawable)
128 | {
129 | ImageView view = getView(viewId);
130 | view.setImageDrawable(drawable);
131 | return this;
132 | }
133 |
134 | public ViewHolder setBackgroundColor(int viewId, int color)
135 | {
136 | View view = getView(viewId);
137 | view.setBackgroundColor(color);
138 | return this;
139 | }
140 |
141 | public ViewHolder setBackgroundRes(int viewId, int backgroundRes)
142 | {
143 | View view = getView(viewId);
144 | view.setBackgroundResource(backgroundRes);
145 | return this;
146 | }
147 |
148 | public ViewHolder setTextColor(int viewId, int textColor)
149 | {
150 | TextView view = getView(viewId);
151 | view.setTextColor(textColor);
152 | return this;
153 | }
154 |
155 | public ViewHolder setTextColorRes(int viewId, int textColorRes)
156 | {
157 | TextView view = getView(viewId);
158 | view.setTextColor(mContext.getResources().getColor(textColorRes));
159 | return this;
160 | }
161 |
162 | @SuppressLint("NewApi")
163 | public ViewHolder setAlpha(int viewId, float value)
164 | {
165 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
166 | {
167 | getView(viewId).setAlpha(value);
168 | } else
169 | {
170 | // Pre-honeycomb hack to set Alpha value
171 | AlphaAnimation alpha = new AlphaAnimation(value, value);
172 | alpha.setDuration(0);
173 | alpha.setFillAfter(true);
174 | getView(viewId).startAnimation(alpha);
175 | }
176 | return this;
177 | }
178 |
179 | public ViewHolder setVisible(int viewId, boolean visible)
180 | {
181 | View view = getView(viewId);
182 | view.setVisibility(visible ? View.VISIBLE : View.GONE);
183 | return this;
184 | }
185 |
186 | public ViewHolder linkify(int viewId)
187 | {
188 | TextView view = getView(viewId);
189 | Linkify.addLinks(view, Linkify.ALL);
190 | return this;
191 | }
192 |
193 | public ViewHolder setTypeface(Typeface typeface, int... viewIds)
194 | {
195 | for (int viewId : viewIds)
196 | {
197 | TextView view = getView(viewId);
198 | view.setTypeface(typeface);
199 | view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
200 | }
201 | return this;
202 | }
203 |
204 | public ViewHolder setProgress(int viewId, int progress)
205 | {
206 | ProgressBar view = getView(viewId);
207 | view.setProgress(progress);
208 | return this;
209 | }
210 |
211 | public ViewHolder setProgress(int viewId, int progress, int max)
212 | {
213 | ProgressBar view = getView(viewId);
214 | view.setMax(max);
215 | view.setProgress(progress);
216 | return this;
217 | }
218 |
219 | public ViewHolder setMax(int viewId, int max)
220 | {
221 | ProgressBar view = getView(viewId);
222 | view.setMax(max);
223 | return this;
224 | }
225 |
226 | public ViewHolder setRating(int viewId, float rating)
227 | {
228 | RatingBar view = getView(viewId);
229 | view.setRating(rating);
230 | return this;
231 | }
232 |
233 | public ViewHolder setRating(int viewId, float rating, int max)
234 | {
235 | RatingBar view = getView(viewId);
236 | view.setMax(max);
237 | view.setRating(rating);
238 | return this;
239 | }
240 |
241 | public ViewHolder setTag(int viewId, Object tag)
242 | {
243 | View view = getView(viewId);
244 | view.setTag(tag);
245 | return this;
246 | }
247 |
248 | public ViewHolder setTag(int viewId, int key, Object tag)
249 | {
250 | View view = getView(viewId);
251 | view.setTag(key, tag);
252 | return this;
253 | }
254 |
255 | public ViewHolder setChecked(int viewId, boolean checked)
256 | {
257 | Checkable view = (Checkable) getView(viewId);
258 | view.setChecked(checked);
259 | return this;
260 | }
261 |
262 | /**
263 | * 关于事件的
264 | */
265 | public ViewHolder setOnClickListener(int viewId,
266 | View.OnClickListener listener)
267 | {
268 | View view = getView(viewId);
269 | view.setOnClickListener(listener);
270 | return this;
271 | }
272 |
273 | public ViewHolder setOnTouchListener(int viewId,
274 | View.OnTouchListener listener)
275 | {
276 | View view = getView(viewId);
277 | view.setOnTouchListener(listener);
278 | return this;
279 | }
280 |
281 | public ViewHolder setOnLongClickListener(int viewId,
282 | View.OnLongClickListener listener)
283 | {
284 | View view = getView(viewId);
285 | view.setOnLongClickListener(listener);
286 | return this;
287 | }
288 |
289 |
290 | }
291 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/abslistview/base/ItemViewDelegate.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.abslistview.base;
2 |
3 |
4 | import choose.lm.com.fileselector.base.abslistview.ViewHolder;
5 |
6 | /**
7 | * Created by zhy on 16/6/22.
8 | */
9 | public interface ItemViewDelegate
10 | {
11 |
12 | public abstract int getItemViewLayoutId();
13 |
14 | public abstract boolean isForViewType(T item, int position);
15 |
16 | public abstract void convert(ViewHolder holder, T t, int position);
17 |
18 |
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/abslistview/base/ItemViewDelegateManager.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.abslistview.base;
2 |
3 | import android.support.v4.util.SparseArrayCompat;
4 |
5 | import choose.lm.com.fileselector.base.abslistview.ViewHolder;
6 |
7 |
8 | /**
9 | * Created by zhy on 16/6/22.
10 | */
11 | public class ItemViewDelegateManager
12 | {
13 | SparseArrayCompat> delegates = new SparseArrayCompat();
14 |
15 | public int getItemViewDelegateCount()
16 | {
17 | return delegates.size();
18 | }
19 |
20 | public ItemViewDelegateManager addDelegate(ItemViewDelegate delegate)
21 | {
22 | int viewType = delegates.size();
23 | if (delegate != null)
24 | {
25 | delegates.put(viewType, delegate);
26 | viewType++;
27 | }
28 | return this;
29 | }
30 |
31 | public ItemViewDelegateManager addDelegate(int viewType, ItemViewDelegate delegate)
32 | {
33 | if (delegates.get(viewType) != null)
34 | {
35 | throw new IllegalArgumentException(
36 | "An ItemViewDelegate is already registered for the viewType = "
37 | + viewType
38 | + ". Already registered ItemViewDelegate is "
39 | + delegates.get(viewType));
40 | }
41 | delegates.put(viewType, delegate);
42 | return this;
43 | }
44 |
45 | public ItemViewDelegateManager removeDelegate(ItemViewDelegate delegate)
46 | {
47 | if (delegate == null)
48 | {
49 | throw new NullPointerException("ItemViewDelegate is null");
50 | }
51 | int indexToRemove = delegates.indexOfValue(delegate);
52 |
53 | if (indexToRemove >= 0)
54 | {
55 | delegates.removeAt(indexToRemove);
56 | }
57 | return this;
58 | }
59 |
60 | public ItemViewDelegateManager removeDelegate(int itemType)
61 | {
62 | int indexToRemove = delegates.indexOfKey(itemType);
63 |
64 | if (indexToRemove >= 0)
65 | {
66 | delegates.removeAt(indexToRemove);
67 | }
68 | return this;
69 | }
70 |
71 | public int getItemViewType(T item, int position)
72 | {
73 | int delegatesCount = delegates.size();
74 | for (int i = delegatesCount - 1; i >= 0; i--)
75 | {
76 | ItemViewDelegate delegate = delegates.valueAt(i);
77 | if (delegate.isForViewType(item, position))
78 | {
79 | return delegates.keyAt(i);
80 | }
81 | }
82 | throw new IllegalArgumentException(
83 | "No ItemViewDelegate added that matches position=" + position + " in data source");
84 | }
85 |
86 | public void convert(ViewHolder holder, T item, int position)
87 | {
88 | int delegatesCount = delegates.size();
89 | for (int i = 0; i < delegatesCount; i++)
90 | {
91 | ItemViewDelegate delegate = delegates.valueAt(i);
92 |
93 | if (delegate.isForViewType(item, position))
94 | {
95 | delegate.convert(holder, item, position);
96 | return;
97 | }
98 | }
99 | throw new IllegalArgumentException(
100 | "No ItemViewDelegateManager added that matches position=" + position + " in data source");
101 | }
102 |
103 |
104 | public int getItemViewLayoutId(int viewType)
105 | {
106 | return delegates.get(viewType).getItemViewLayoutId();
107 | }
108 |
109 | public int getItemViewType(ItemViewDelegate itemViewDelegate)
110 | {
111 | return delegates.indexOfValue(itemViewDelegate);
112 | }
113 |
114 | public ItemViewDelegate getItemViewDelegate(T item, int position)
115 | {
116 | int delegatesCount = delegates.size();
117 | for (int i = delegatesCount - 1; i >= 0; i--)
118 | {
119 | ItemViewDelegate delegate = delegates.valueAt(i);
120 | if (delegate.isForViewType(item, position))
121 | {
122 | return delegate;
123 | }
124 | }
125 | throw new IllegalArgumentException(
126 | "No ItemViewDelegate added that matches position=" + position + " in data source");
127 | }
128 |
129 | public int getItemViewLayoutId(T item, int position)
130 | {
131 | return getItemViewDelegate(item,position).getItemViewLayoutId();
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/CommonAdapter.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 |
6 | import java.util.List;
7 |
8 | import choose.lm.com.fileselector.base.recyclerview.base.ItemViewDelegate;
9 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
10 |
11 |
12 | /**
13 | * Created by zhy on 16/4/9.
14 | */
15 | public abstract class CommonAdapter extends MultiItemTypeAdapter {
16 | protected Context mContext;
17 | protected int mLayoutId;
18 | protected List mDatas;
19 | protected LayoutInflater mInflater;
20 |
21 | public CommonAdapter(final Context context, final int layoutId, List datas) {
22 | super(context, datas);
23 | mContext = context;
24 | mInflater = LayoutInflater.from(context);
25 | mLayoutId = layoutId;
26 | mDatas = datas;
27 | addItemViewDelegate(new ItemViewDelegate() {
28 | @Override
29 | public int getItemViewLayoutId() {
30 | return layoutId;
31 | }
32 |
33 | @Override
34 | public boolean isForViewType(T item, int position) {
35 | return true;
36 | }
37 |
38 | @Override
39 | public void convert(ViewHolder holder, T t, int position) {
40 | CommonAdapter.this.convert(holder, t, position);
41 | }
42 | });
43 | }
44 |
45 |
46 |
47 |
48 | protected abstract void convert(ViewHolder holder, T t, int position);
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/MultiItemTypeAdapter.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import java.util.List;
9 |
10 | import choose.lm.com.fileselector.base.recyclerview.base.ItemViewDelegate;
11 | import choose.lm.com.fileselector.base.recyclerview.base.ItemViewDelegateManager;
12 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
13 |
14 |
15 | /**
16 | * Created by zhy on 16/4/9.
17 | */
18 | public class MultiItemTypeAdapter extends RecyclerView.Adapter {
19 | protected Context mContext;
20 | protected List mDatas;
21 |
22 | protected ItemViewDelegateManager mItemViewDelegateManager;
23 | protected OnItemClickListener mOnItemClickListener;
24 |
25 |
26 | public MultiItemTypeAdapter(Context context, List datas) {
27 | mContext = context;
28 | mDatas = datas;
29 | mItemViewDelegateManager = new ItemViewDelegateManager();
30 | }
31 |
32 | @Override
33 | public int getItemViewType(int position) {
34 | if (!useItemViewDelegateManager()) return super.getItemViewType(position);
35 | return mItemViewDelegateManager.getItemViewType(mDatas.get(position), position);
36 | }
37 |
38 |
39 | @Override
40 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
41 | ItemViewDelegate itemViewDelegate = mItemViewDelegateManager.getItemViewDelegate(viewType);
42 | int layoutId = itemViewDelegate.getItemViewLayoutId();
43 | ViewHolder holder = ViewHolder.createViewHolder(mContext, parent, layoutId);
44 | onViewHolderCreated(holder,holder.getConvertView());
45 | setListener(parent, holder, viewType);
46 | return holder;
47 | }
48 |
49 | public void onViewHolderCreated(ViewHolder holder,View itemView){
50 |
51 | }
52 |
53 | public void convert(ViewHolder holder, T t) {
54 | mItemViewDelegateManager.convert(holder, t, holder.getAdapterPosition());
55 | }
56 |
57 | protected boolean isEnabled(int viewType) {
58 | return true;
59 | }
60 |
61 |
62 | protected void setListener(final ViewGroup parent, final ViewHolder viewHolder, int viewType) {
63 | if (!isEnabled(viewType)) return;
64 | viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | if (mOnItemClickListener != null) {
68 | int position = viewHolder.getAdapterPosition();
69 | mOnItemClickListener.onItemClick(v, viewHolder , position);
70 | }
71 | }
72 | });
73 |
74 | viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() {
75 | @Override
76 | public boolean onLongClick(View v) {
77 | if (mOnItemClickListener != null) {
78 | int position = viewHolder.getAdapterPosition();
79 | return mOnItemClickListener.onItemLongClick(v, viewHolder, position);
80 | }
81 | return false;
82 | }
83 | });
84 | }
85 |
86 | @Override
87 | public void onBindViewHolder(ViewHolder holder, int position) {
88 | convert(holder, mDatas.get(position));
89 | }
90 |
91 | @Override
92 | public int getItemCount() {
93 | int itemCount = mDatas.size();
94 | return itemCount;
95 | }
96 |
97 |
98 | public List getDatas() {
99 | return mDatas;
100 | }
101 | public void setDatas(List data) {
102 | mDatas=data;
103 | notifyDataSetChanged();
104 | }
105 |
106 | public MultiItemTypeAdapter addItemViewDelegate(ItemViewDelegate itemViewDelegate) {
107 | mItemViewDelegateManager.addDelegate(itemViewDelegate);
108 | return this;
109 | }
110 |
111 | public MultiItemTypeAdapter addItemViewDelegate(int viewType, ItemViewDelegate itemViewDelegate) {
112 | mItemViewDelegateManager.addDelegate(viewType, itemViewDelegate);
113 | return this;
114 | }
115 |
116 | protected boolean useItemViewDelegateManager() {
117 | return mItemViewDelegateManager.getItemViewDelegateCount() > 0;
118 | }
119 |
120 | public interface OnItemClickListener {
121 | void onItemClick(View view, RecyclerView.ViewHolder holder, int position);
122 |
123 | boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position);
124 | }
125 |
126 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
127 | this.mOnItemClickListener = onItemClickListener;
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/base/ItemViewDelegate.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview.base;
2 |
3 |
4 | /**
5 | * Created by zhy on 16/6/22.
6 | */
7 | public interface ItemViewDelegate
8 | {
9 |
10 | int getItemViewLayoutId();
11 |
12 | boolean isForViewType(T item, int position);
13 |
14 | void convert(ViewHolder holder, T t, int position);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/base/ItemViewDelegateManager.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview.base;
2 |
3 | import android.support.v4.util.SparseArrayCompat;
4 |
5 |
6 | /**
7 | * Created by zhy on 16/6/22.
8 | */
9 | public class ItemViewDelegateManager
10 | {
11 | SparseArrayCompat> delegates = new SparseArrayCompat();
12 |
13 | public int getItemViewDelegateCount()
14 | {
15 | return delegates.size();
16 | }
17 |
18 | public ItemViewDelegateManager addDelegate(ItemViewDelegate delegate)
19 | {
20 | int viewType = delegates.size();
21 | if (delegate != null)
22 | {
23 | delegates.put(viewType, delegate);
24 | viewType++;
25 | }
26 | return this;
27 | }
28 |
29 | public ItemViewDelegateManager addDelegate(int viewType, ItemViewDelegate delegate)
30 | {
31 | if (delegates.get(viewType) != null)
32 | {
33 | throw new IllegalArgumentException(
34 | "An ItemViewDelegate is already registered for the viewType = "
35 | + viewType
36 | + ". Already registered ItemViewDelegate is "
37 | + delegates.get(viewType));
38 | }
39 | delegates.put(viewType, delegate);
40 | return this;
41 | }
42 |
43 | public ItemViewDelegateManager removeDelegate(ItemViewDelegate delegate)
44 | {
45 | if (delegate == null)
46 | {
47 | throw new NullPointerException("ItemViewDelegate is null");
48 | }
49 | int indexToRemove = delegates.indexOfValue(delegate);
50 |
51 | if (indexToRemove >= 0)
52 | {
53 | delegates.removeAt(indexToRemove);
54 | }
55 | return this;
56 | }
57 |
58 | public ItemViewDelegateManager removeDelegate(int itemType)
59 | {
60 | int indexToRemove = delegates.indexOfKey(itemType);
61 |
62 | if (indexToRemove >= 0)
63 | {
64 | delegates.removeAt(indexToRemove);
65 | }
66 | return this;
67 | }
68 |
69 | public int getItemViewType(T item, int position)
70 | {
71 | int delegatesCount = delegates.size();
72 | for (int i = delegatesCount - 1; i >= 0; i--)
73 | {
74 | ItemViewDelegate delegate = delegates.valueAt(i);
75 | if (delegate.isForViewType( item, position))
76 | {
77 | return delegates.keyAt(i);
78 | }
79 | }
80 | throw new IllegalArgumentException(
81 | "No ItemViewDelegate added that matches position=" + position + " in data source");
82 | }
83 |
84 | public void convert(ViewHolder holder, T item, int position)
85 | {
86 | int delegatesCount = delegates.size();
87 | for (int i = 0; i < delegatesCount; i++)
88 | {
89 | ItemViewDelegate delegate = delegates.valueAt(i);
90 |
91 | if (delegate.isForViewType( item, position))
92 | {
93 | delegate.convert(holder, item, position);
94 | return;
95 | }
96 | }
97 | throw new IllegalArgumentException(
98 | "No ItemViewDelegateManager added that matches position=" + position + " in data source");
99 | }
100 |
101 |
102 | public ItemViewDelegate getItemViewDelegate(int viewType)
103 | {
104 | return delegates.get(viewType);
105 | }
106 |
107 | public int getItemViewLayoutId(int viewType)
108 | {
109 | return getItemViewDelegate(viewType).getItemViewLayoutId();
110 | }
111 |
112 | public int getItemViewType(ItemViewDelegate itemViewDelegate)
113 | {
114 | return delegates.indexOfValue(itemViewDelegate);
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/base/ViewHolder.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview.base;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Paint;
7 | import android.graphics.Typeface;
8 | import android.graphics.drawable.Drawable;
9 | import android.os.Build;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.text.util.Linkify;
12 | import android.util.SparseArray;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.view.animation.AlphaAnimation;
17 | import android.widget.Checkable;
18 | import android.widget.ImageView;
19 | import android.widget.ProgressBar;
20 | import android.widget.RatingBar;
21 | import android.widget.TextView;
22 |
23 | import com.bumptech.glide.Glide;
24 |
25 | import java.io.File;
26 |
27 | import choose.lm.com.fileselector.R;
28 |
29 |
30 | public class ViewHolder extends RecyclerView.ViewHolder {
31 | private SparseArray mViews;
32 | private View mConvertView;
33 | private Context mContext;
34 |
35 | public ViewHolder(Context context, View itemView) {
36 | super(itemView);
37 | mContext = context;
38 | mConvertView = itemView;
39 | mViews = new SparseArray();
40 | }
41 |
42 |
43 | public static ViewHolder createViewHolder(Context context, View itemView) {
44 | ViewHolder holder = new ViewHolder(context, itemView);
45 | return holder;
46 | }
47 |
48 | public static ViewHolder createViewHolder(Context context,
49 | ViewGroup parent, int layoutId) {
50 | View itemView = LayoutInflater.from(context).inflate(layoutId, parent,
51 | false);
52 | ViewHolder holder = new ViewHolder(context, itemView);
53 | return holder;
54 | }
55 |
56 |
57 |
58 | /**
59 | * 通过viewId获取控件
60 | *
61 | * @param viewId
62 | * @return
63 | */
64 | public T getView(int viewId) {
65 | View view = mViews.get(viewId);
66 | if (view == null) {
67 | view = mConvertView.findViewById(viewId);
68 | mViews.put(viewId, view);
69 | }
70 | return (T) view;
71 | }
72 |
73 | public View getConvertView() {
74 | return mConvertView;
75 | }
76 |
77 | /**
78 | * 设置图片-ImageView
79 | *
80 | * @param viewId ImageViewID
81 | * @param imageFile 图片地址
82 | * @param parms 参数
83 | * @return
84 | */
85 | public ViewHolder setImageFile(int viewId, File imageFile, float thumbnail, final int... parms)
86 | {
87 | ImageView view = getView(viewId);
88 | Glide.with(mContext).load(imageFile).placeholder(R.drawable.img_preloading).thumbnail(thumbnail).into(view);
89 | return this;
90 | }
91 | /****以下为辅助方法*****/
92 |
93 | /**
94 | * 设置TextView的值
95 | *
96 | * @param viewId
97 | * @param text
98 | * @return
99 | */
100 | public ViewHolder setText(int viewId, String text) {
101 | TextView tv = getView(viewId);
102 | tv.setText(text);
103 | return this;
104 | }
105 |
106 | public ViewHolder setImageResource(int viewId, int resId) {
107 | ImageView view = getView(viewId);
108 | view.setImageResource(resId);
109 | return this;
110 | }
111 |
112 | public ViewHolder setSelected(int viewId, boolean isbool) {
113 | View view = getView(viewId);
114 | view.setSelected(isbool);
115 | return this;
116 | }
117 |
118 | public ViewHolder setImageBitmap(int viewId, Bitmap bitmap) {
119 | ImageView view = getView(viewId);
120 | view.setImageBitmap(bitmap);
121 | return this;
122 | }
123 |
124 | /*public ViewHolder setImageurl(int viewId, String url, int defaultimg, float... parms) {
125 | ImageView view = getView(viewId);
126 | DrawableTypeRequest load = Glide.with(mContext).load(url);
127 | if (parms.length > 0) {
128 | load.thumbnail(parms[0]);
129 | }
130 | if (defaultimg != 0) {
131 | load.placeholder(defaultimg);
132 | }
133 | load.dontAnimate();
134 | load.into(view);
135 | return this;
136 | }*/
137 |
138 | public ViewHolder setImageDrawable(int viewId, Drawable drawable) {
139 | ImageView view = getView(viewId);
140 | view.setImageDrawable(drawable);
141 | return this;
142 | }
143 |
144 | public ViewHolder setBackgroundColor(int viewId, int color) {
145 | View view = getView(viewId);
146 | view.setBackgroundColor(color);
147 | return this;
148 | }
149 |
150 | public ViewHolder setBackgroundRes(int viewId, int backgroundRes) {
151 | View view = getView(viewId);
152 | view.setBackgroundResource(backgroundRes);
153 | return this;
154 | }
155 |
156 | public ViewHolder setTextColor(int viewId, int textColor) {
157 | TextView view = getView(viewId);
158 | view.setTextColor(textColor);
159 | return this;
160 | }
161 |
162 | public ViewHolder setTextColorRes(int viewId, int textColorRes) {
163 | TextView view = getView(viewId);
164 | view.setTextColor(mContext.getResources().getColor(textColorRes));
165 | return this;
166 | }
167 |
168 | @SuppressLint("NewApi")
169 | public ViewHolder setAlpha(int viewId, float value) {
170 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
171 | getView(viewId).setAlpha(value);
172 | } else {
173 | // Pre-honeycomb hack to set Alpha value
174 | AlphaAnimation alpha = new AlphaAnimation(value, value);
175 | alpha.setDuration(0);
176 | alpha.setFillAfter(true);
177 | getView(viewId).startAnimation(alpha);
178 | }
179 | return this;
180 | }
181 |
182 | public ViewHolder setVisible(int viewId, boolean visible) {
183 | View view = getView(viewId);
184 | view.setVisibility(visible ? View.VISIBLE : View.GONE);
185 | return this;
186 | }
187 |
188 | public ViewHolder linkify(int viewId) {
189 | TextView view = getView(viewId);
190 | Linkify.addLinks(view, Linkify.ALL);
191 | return this;
192 | }
193 |
194 | public ViewHolder setTypeface(Typeface typeface, int... viewIds) {
195 | for (int viewId : viewIds) {
196 | TextView view = getView(viewId);
197 | view.setTypeface(typeface);
198 | view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
199 | }
200 | return this;
201 | }
202 |
203 | public ViewHolder setProgress(int viewId, int progress) {
204 | ProgressBar view = getView(viewId);
205 | view.setProgress(progress);
206 | return this;
207 | }
208 |
209 | public ViewHolder setProgress(int viewId, int progress, int max) {
210 | ProgressBar view = getView(viewId);
211 | view.setMax(max);
212 | view.setProgress(progress);
213 | return this;
214 | }
215 |
216 | public ViewHolder setMax(int viewId, int max) {
217 | ProgressBar view = getView(viewId);
218 | view.setMax(max);
219 | return this;
220 | }
221 |
222 | public ViewHolder setRating(int viewId, float rating) {
223 | RatingBar view = getView(viewId);
224 | view.setRating(rating);
225 | return this;
226 | }
227 |
228 | public ViewHolder setRating(int viewId, float rating, int max) {
229 | RatingBar view = getView(viewId);
230 | view.setMax(max);
231 | view.setRating(rating);
232 | return this;
233 | }
234 |
235 | public ViewHolder setTag(int viewId, Object tag) {
236 | View view = getView(viewId);
237 | view.setTag(tag);
238 | return this;
239 | }
240 |
241 | public ViewHolder setTag(int viewId, int key, Object tag) {
242 | View view = getView(viewId);
243 | view.setTag(key, tag);
244 | return this;
245 | }
246 |
247 | public ViewHolder setChecked(int viewId, boolean checked) {
248 | Checkable view = (Checkable) getView(viewId);
249 | view.setChecked(checked);
250 | return this;
251 | }
252 |
253 | public ViewHolder setSelect(int viewId, boolean checked) {
254 | View view = getView(viewId);
255 | view.setSelected(checked);
256 | return this;
257 | }
258 |
259 | /**
260 | * 关于事件的
261 | */
262 | public ViewHolder setOnClickListener(int viewId, View.OnClickListener listener) {
263 | View view = getView(viewId);
264 | view.setOnClickListener(listener);
265 | return this;
266 | }
267 |
268 | public ViewHolder setOnTouchListener(int viewId, View.OnTouchListener listener) {
269 | View view = getView(viewId);
270 | view.setOnTouchListener(listener);
271 | return this;
272 | }
273 |
274 | public ViewHolder setOnLongClickListener(int viewId, View.OnLongClickListener listener) {
275 | View view = getView(viewId);
276 | view.setOnLongClickListener(listener);
277 | return this;
278 | }
279 |
280 |
281 | }
282 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/utils/WrapperUtils.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview.utils;
2 |
3 | import android.support.v7.widget.GridLayoutManager;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.support.v7.widget.StaggeredGridLayoutManager;
6 | import android.view.ViewGroup;
7 |
8 | /**
9 | * Created by zhy on 16/6/28.
10 | */
11 | public class WrapperUtils
12 | {
13 | public interface SpanSizeCallback
14 | {
15 | int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position);
16 | }
17 |
18 | public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback)
19 | {
20 | innerAdapter.onAttachedToRecyclerView(recyclerView);
21 |
22 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
23 | if (layoutManager instanceof GridLayoutManager)
24 | {
25 | final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
26 | final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
27 |
28 | gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()
29 | {
30 | @Override
31 | public int getSpanSize(int position)
32 | {
33 | return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
34 | }
35 | });
36 | gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
37 | }
38 | }
39 |
40 | public static void setFullSpan(RecyclerView.ViewHolder holder)
41 | {
42 | ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
43 |
44 | if (lp != null
45 | && lp instanceof StaggeredGridLayoutManager.LayoutParams)
46 | {
47 |
48 | StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
49 |
50 | p.setFullSpan(true);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/wrapper/EmptyWrapper.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview.wrapper;
2 |
3 | import android.support.v7.widget.GridLayoutManager;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
9 | import choose.lm.com.fileselector.base.recyclerview.utils.WrapperUtils;
10 |
11 |
12 | /**
13 | * Created by zhy on 16/6/23.
14 | */
15 | public class EmptyWrapper extends RecyclerView.Adapter
16 | {
17 | public static final int ITEM_TYPE_EMPTY = Integer.MAX_VALUE - 1;
18 |
19 | private RecyclerView.Adapter mInnerAdapter;
20 | private View mEmptyView;
21 | private int mEmptyLayoutId;
22 |
23 |
24 | public EmptyWrapper(RecyclerView.Adapter adapter)
25 | {
26 | mInnerAdapter = adapter;
27 | }
28 |
29 | private boolean isEmpty()
30 | {
31 | return (mEmptyView != null || mEmptyLayoutId != 0) && mInnerAdapter.getItemCount() == 0;
32 | }
33 |
34 | @Override
35 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
36 | {
37 | if (isEmpty())
38 | {
39 | ViewHolder holder;
40 | if (mEmptyView != null)
41 | {
42 | holder = ViewHolder.createViewHolder(parent.getContext(), mEmptyView);
43 | } else
44 | {
45 | holder = ViewHolder.createViewHolder(parent.getContext(), parent, mEmptyLayoutId);
46 | }
47 | return holder;
48 | }
49 | return mInnerAdapter.onCreateViewHolder(parent, viewType);
50 | }
51 |
52 | @Override
53 | public void onAttachedToRecyclerView(RecyclerView recyclerView)
54 | {
55 | WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback() {
56 | @Override
57 | public int getSpanSize(GridLayoutManager gridLayoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position) {
58 | if (isEmpty()) {
59 | return gridLayoutManager.getSpanCount();
60 | }
61 | if (oldLookup != null) {
62 | return oldLookup.getSpanSize(position);
63 | }
64 | return 1;
65 | }
66 | });
67 |
68 |
69 | }
70 |
71 | @Override
72 | public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
73 | {
74 | mInnerAdapter.onViewAttachedToWindow(holder);
75 | if (isEmpty())
76 | {
77 | WrapperUtils.setFullSpan(holder);
78 | }
79 | }
80 |
81 |
82 | @Override
83 | public int getItemViewType(int position)
84 | {
85 | if (isEmpty())
86 | {
87 | return ITEM_TYPE_EMPTY;
88 | }
89 | return mInnerAdapter.getItemViewType(position);
90 | }
91 |
92 | @Override
93 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
94 | {
95 | if (isEmpty())
96 | {
97 | return;
98 | }
99 | mInnerAdapter.onBindViewHolder(holder, position);
100 | }
101 |
102 | @Override
103 | public int getItemCount()
104 | {
105 | if (isEmpty()) return 1;
106 | return mInnerAdapter.getItemCount();
107 | }
108 |
109 |
110 |
111 | public void setEmptyView(View emptyView)
112 | {
113 | mEmptyView = emptyView;
114 | }
115 |
116 | public void setEmptyView(int layoutId)
117 | {
118 | mEmptyLayoutId = layoutId;
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/wrapper/HeaderAndFooterWrapper.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview.wrapper;
2 |
3 | import android.support.v4.util.SparseArrayCompat;
4 | import android.support.v7.widget.GridLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
10 | import choose.lm.com.fileselector.base.recyclerview.utils.WrapperUtils;
11 |
12 |
13 | /**
14 | * Created by zhy on 16/6/23.
15 | */
16 | public class HeaderAndFooterWrapper extends RecyclerView.Adapter
17 | {
18 | private static final int BASE_ITEM_TYPE_HEADER = 100000;
19 | private static final int BASE_ITEM_TYPE_FOOTER = 200000;
20 |
21 | private SparseArrayCompat mHeaderViews = new SparseArrayCompat<>();
22 | private SparseArrayCompat mFootViews = new SparseArrayCompat<>();
23 |
24 | private RecyclerView.Adapter mInnerAdapter;
25 |
26 | public HeaderAndFooterWrapper(RecyclerView.Adapter adapter)
27 | {
28 | mInnerAdapter = adapter;
29 | }
30 |
31 | @Override
32 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
33 | {
34 | if (mHeaderViews.get(viewType) != null)
35 | {
36 | ViewHolder holder = ViewHolder.createViewHolder(parent.getContext(), mHeaderViews.get(viewType));
37 | return holder;
38 |
39 | } else if (mFootViews.get(viewType) != null)
40 | {
41 | ViewHolder holder = ViewHolder.createViewHolder(parent.getContext(), mFootViews.get(viewType));
42 | return holder;
43 | }
44 | return mInnerAdapter.onCreateViewHolder(parent, viewType);
45 | }
46 |
47 | @Override
48 | public int getItemViewType(int position)
49 | {
50 | if (isHeaderViewPos(position))
51 | {
52 | return mHeaderViews.keyAt(position);
53 | } else if (isFooterViewPos(position))
54 | {
55 | return mFootViews.keyAt(position - getHeadersCount() - getRealItemCount());
56 | }
57 | return mInnerAdapter.getItemViewType(position - getHeadersCount());
58 | }
59 |
60 | private int getRealItemCount()
61 | {
62 | return mInnerAdapter.getItemCount();
63 | }
64 |
65 |
66 | @Override
67 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
68 | {
69 | if (isHeaderViewPos(position))
70 | {
71 | return;
72 | }
73 | if (isFooterViewPos(position))
74 | {
75 | return;
76 | }
77 | mInnerAdapter.onBindViewHolder(holder, position - getHeadersCount());
78 | }
79 |
80 | @Override
81 | public int getItemCount()
82 | {
83 | return getHeadersCount() + getFootersCount() + getRealItemCount();
84 | }
85 |
86 | @Override
87 | public void onAttachedToRecyclerView(RecyclerView recyclerView)
88 | {
89 | WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback() {
90 | @Override
91 | public int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position) {
92 | int viewType = getItemViewType(position);
93 | if (mHeaderViews.get(viewType) != null) {
94 | return layoutManager.getSpanCount();
95 | } else if (mFootViews.get(viewType) != null) {
96 | return layoutManager.getSpanCount();
97 | }
98 | if (oldLookup != null)
99 | return oldLookup.getSpanSize(position);
100 | return 1;
101 | }
102 | });
103 | }
104 |
105 | @Override
106 | public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
107 | {
108 | mInnerAdapter.onViewAttachedToWindow(holder);
109 | int position = holder.getLayoutPosition();
110 | if (isHeaderViewPos(position) || isFooterViewPos(position))
111 | {
112 | WrapperUtils.setFullSpan(holder);
113 | }
114 | }
115 |
116 | private boolean isHeaderViewPos(int position)
117 | {
118 | return position < getHeadersCount();
119 | }
120 |
121 | private boolean isFooterViewPos(int position)
122 | {
123 | return position >= getHeadersCount() + getRealItemCount();
124 | }
125 |
126 |
127 | public void addHeaderView(View view)
128 | {
129 | mHeaderViews.put(mHeaderViews.size() + BASE_ITEM_TYPE_HEADER, view);
130 | }
131 |
132 | public void addFootView(View view)
133 | {
134 | mFootViews.put(mFootViews.size() + BASE_ITEM_TYPE_FOOTER, view);
135 | }
136 |
137 | public int getHeadersCount()
138 | {
139 | return mHeaderViews.size();
140 | }
141 |
142 | public int getFootersCount()
143 | {
144 | return mFootViews.size();
145 | }
146 |
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/base/recyclerview/wrapper/LoadmoreWrapper.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.base.recyclerview.wrapper;
2 |
3 | import android.support.v7.widget.GridLayoutManager;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.support.v7.widget.StaggeredGridLayoutManager;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
10 | import choose.lm.com.fileselector.base.recyclerview.utils.WrapperUtils;
11 |
12 |
13 | /**
14 | * Created by zhy on 16/6/23.
15 | */
16 | public class LoadmoreWrapper extends RecyclerView.Adapter
17 | {
18 | public static final int ITEM_TYPE_LOAD_MORE = Integer.MAX_VALUE - 2;
19 |
20 | private RecyclerView.Adapter mInnerAdapter;
21 | private View mLoadMoreView;
22 | private int mLoadMoreLayoutId;
23 |
24 | public LoadmoreWrapper(RecyclerView.Adapter adapter)
25 | {
26 | mInnerAdapter = adapter;
27 | }
28 |
29 | private boolean hasLoadMore()
30 | {
31 | return mLoadMoreView != null || mLoadMoreLayoutId != 0;
32 | }
33 |
34 |
35 | private boolean isShowLoadMore(int position)
36 | {
37 | return hasLoadMore() && (position >= mInnerAdapter.getItemCount());
38 | }
39 |
40 | @Override
41 | public int getItemViewType(int position)
42 | {
43 | if (isShowLoadMore(position))
44 | {
45 | return ITEM_TYPE_LOAD_MORE;
46 | }
47 | return mInnerAdapter.getItemViewType(position);
48 | }
49 |
50 | @Override
51 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
52 | {
53 | if (viewType == ITEM_TYPE_LOAD_MORE)
54 | {
55 | ViewHolder holder;
56 | if (mLoadMoreView != null)
57 | {
58 | holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView);
59 | } else
60 | {
61 | holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId);
62 | }
63 | return holder;
64 | }
65 | return mInnerAdapter.onCreateViewHolder(parent, viewType);
66 | }
67 |
68 | @Override
69 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
70 | {
71 | if (isShowLoadMore(position))
72 | {
73 | if (mOnLoadMoreListener != null)
74 | {
75 | mOnLoadMoreListener.onLoadMoreRequested();
76 | }
77 | return;
78 | }
79 | mInnerAdapter.onBindViewHolder(holder, position);
80 | }
81 |
82 | @Override
83 | public void onAttachedToRecyclerView(RecyclerView recyclerView)
84 | {
85 | WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback() {
86 | @Override
87 | public int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position) {
88 | if (isShowLoadMore(position)) {
89 | return layoutManager.getSpanCount();
90 | }
91 | if (oldLookup != null) {
92 | return oldLookup.getSpanSize(position);
93 | }
94 | return 1;
95 | }
96 | });
97 | }
98 |
99 |
100 | @Override
101 | public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
102 | {
103 | mInnerAdapter.onViewAttachedToWindow(holder);
104 |
105 | if (isShowLoadMore(holder.getLayoutPosition()))
106 | {
107 | setFullSpan(holder);
108 | }
109 | }
110 |
111 | private void setFullSpan(RecyclerView.ViewHolder holder)
112 | {
113 | ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
114 |
115 | if (lp != null
116 | && lp instanceof StaggeredGridLayoutManager.LayoutParams)
117 | {
118 | StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
119 |
120 | p.setFullSpan(true);
121 | }
122 | }
123 |
124 | @Override
125 | public int getItemCount()
126 | {
127 | return mInnerAdapter.getItemCount() + (hasLoadMore() ? 1 : 0);
128 | }
129 |
130 |
131 | public interface OnLoadMoreListener
132 | {
133 | void onLoadMoreRequested();
134 | }
135 |
136 | private OnLoadMoreListener mOnLoadMoreListener;
137 |
138 | public LoadmoreWrapper setOnLoadMoreListener(OnLoadMoreListener loadMoreListener)
139 | {
140 | if (loadMoreListener != null)
141 | {
142 | mOnLoadMoreListener = loadMoreListener;
143 | }
144 | return this;
145 | }
146 |
147 | public LoadmoreWrapper setLoadMoreView(View loadMoreView)
148 | {
149 | mLoadMoreView = loadMoreView;
150 | return this;
151 | }
152 |
153 | public LoadmoreWrapper setLoadMoreView(int layoutId)
154 | {
155 | mLoadMoreLayoutId = layoutId;
156 | return this;
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/fragments/FileFragment.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.View;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import choose.lm.com.fileselector.R;
14 | import choose.lm.com.fileselector.activitys.ChooseFileActivity;
15 | import choose.lm.com.fileselector.base.BaseFragment;
16 | import choose.lm.com.fileselector.base.MyApplication;
17 | import choose.lm.com.fileselector.base.recyclerview.CommonAdapter;
18 | import choose.lm.com.fileselector.base.recyclerview.MultiItemTypeAdapter;
19 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
20 | import choose.lm.com.fileselector.databinding.LibVideoFragmentBinding;
21 | import choose.lm.com.fileselector.model.FileGroupInfo;
22 | import choose.lm.com.fileselector.model.FileInfo;
23 | import choose.lm.com.fileselector.utils.DateUtil;
24 | import choose.lm.com.fileselector.utils.FileUtil;
25 | import choose.lm.com.fileselector.utils.LoadFiles;
26 |
27 | /**
28 | * Created by Administrator on 2016/11/28 0028.
29 | */
30 | public class FileFragment extends BaseFragment {
31 |
32 | List mDataList = new ArrayList<>();
33 |
34 | private CommonAdapter mGroupAdapter;
35 |
36 |
37 |
38 | @Override
39 | public int getLayoutId() {
40 | return R.layout.lib_video_fragment;
41 | }
42 | private boolean isChoose=false;
43 | /**
44 | * 单选模式 清楚状态
45 | */
46 | public void clearState() {
47 | if (isChoose) {
48 | for (int i = 0; i < mDataList.size(); i++) {
49 | for (int j = 0; j < mDataList.get(i).getmFileList().size(); j++) {
50 | mDataList.get(i).getmFileList().get(j).setIs_select(false);
51 | }
52 | }
53 |
54 | mGroupAdapter.notifyDataSetChanged();
55 |
56 |
57 |
58 | }
59 | }
60 | @Override
61 | protected void initData() {
62 | super.initData();
63 |
64 | }
65 |
66 | @Override
67 | protected void initView(Bundle savedInstanceState) {
68 | super.initView(savedInstanceState);
69 | mGroupAdapter=new CommonAdapter(aty,R.layout.lib_item_file_group,mDataList) {
70 | @Override
71 | protected void convert(final ViewHolder helper, final FileGroupInfo item, final int position) {
72 | if (mDataList.get(position).is_choose()) {
73 | helper.setVisible(R.id.rc_group_content, true);
74 | helper.setSelected(R.id.img_choose, true);
75 | mDataList.get(position).setIs_choose(true);
76 | } else {
77 | helper.setVisible(R.id.rc_group_content, false);
78 | helper.setSelected(R.id.img_choose, false);
79 | mDataList.get(position).setIs_choose(false);
80 | }
81 | helper.setText(R.id.tv_group_name, item.getGroup_name());
82 | RecyclerView content = helper.getView(R.id.rc_group_content);
83 | content.setLayoutManager(new LinearLayoutManager(aty));
84 | content.setAdapter(getmAdapter(item.getmFileList(),position));
85 | helper.setOnClickListener(R.id.lly_choose, new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | if (mDataList.get(position).is_choose()) {
89 | helper.setVisible(R.id.rc_group_content, false);
90 | helper.setSelected(R.id.img_choose, false);
91 | mDataList.get(position).setIs_choose(false);
92 | } else {
93 | helper.setVisible(R.id.rc_group_content, true);
94 | helper.setSelected(R.id.img_choose, true);
95 | mDataList.get(position).setIs_choose(true);
96 | }
97 |
98 | }
99 | });
100 |
101 | }
102 | };
103 | mBinding.rcVideo.setLayoutManager(new LinearLayoutManager(aty));
104 | mBinding.rcVideo.setAdapter(mGroupAdapter);
105 |
106 | loadData();
107 | }
108 |
109 | public void loadData() {
110 | if (MyApplication.getInstance().getContentResolver()!=null) {
111 |
112 | new Thread() {
113 | @Override
114 | public void run() {
115 | super.run();
116 | LoadFiles loadFiles = new LoadFiles();
117 | loadFiles.loadFile(MyApplication.getInstance().getContentResolver());
118 | setDataList(loadFiles.getFiles());
119 | handler.sendEmptyMessage(0);
120 | }
121 | }.start();
122 | }
123 | }
124 | private int groupPo = -1, childPo = -1;
125 | private CommonAdapter mCurAdapter;
126 | public CommonAdapter getmAdapter(List data, final int po)
127 | {
128 | final CommonAdapter mAdapter = new CommonAdapter(aty,R.layout.lib_item_video_fragment,data) {
129 | @Override
130 | protected void convert(ViewHolder helper, FileInfo item, int position) {
131 | if (FileInfo.FileType.WORD.equals(item.getFile_type())) {
132 | helper.setImageResource(R.id.img, R.drawable.ico_word);
133 | } else if (FileInfo.FileType.EXCEL.equals(item.getFile_type())) {
134 | helper.setImageResource(R.id.img, R.drawable.ico_excel);
135 | } else if (FileInfo.FileType.PDF.equals(item.getFile_type())) {
136 | helper.setImageResource(R.id.img, R.drawable.ico_pdf);
137 | } else if (FileInfo.FileType.PPT.equals(item.getFile_type())) {
138 | helper.setImageResource(R.id.img, R.drawable.ico_ppt);
139 | } else {
140 | helper.setImageResource(R.id.img, R.drawable.ico_other);
141 | }
142 |
143 | helper.setText(R.id.tv_time, DateUtil.getCommunityTime(item.getFile_modified_time()));
144 | helper.setText(R.id.tv_name, item.getFile_name());
145 | helper.setText(R.id.tv_size, FileUtil.bytes2kb(item.getFile_size()));
146 |
147 | if (mDataList.get(po).getmFileList().get(position).is_select()) {
148 | helper.setSelected(R.id.imgV_select, true);
149 | } else {
150 | helper.setSelected(R.id.imgV_select, false);
151 | }
152 |
153 | }
154 |
155 | };
156 | mAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
157 | @Override
158 | public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
159 | FileInfo item = mDataList.get(po).getmFileList().get(position);
160 | if (!((ChooseFileActivity) aty).mIsMultiselect) {//单选
161 | ((ChooseFileActivity) aty).clearFile();
162 |
163 | if (item.is_select()) {
164 | view.findViewById(R.id.imgV_select).setSelected(false);
165 | mDataList.get(po).getmFileList().get(position).setIs_select(false);
166 | ((ChooseFileActivity) aty).removeFile(item.getId());
167 | } else {
168 | view.findViewById(R.id.imgV_select).setSelected(true);
169 | mDataList.get(po).getmFileList().get(position).setIs_select(true);
170 | ((ChooseFileActivity) aty).addFile(item);
171 | }
172 |
173 | if (groupPo != -1 && !(groupPo == po && childPo == position)) {
174 | mDataList.get(groupPo).getmFileList().get(childPo).setIs_select(false);
175 | if (groupPo == po) {
176 | int fristPos = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findFirstVisibleItemPosition();
177 | int lastPos = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findLastVisibleItemPosition();
178 | if (groupPo >= fristPos && lastPos <= lastPos) {//当上一项为可见项的时候
179 | View v = mBinding.rcVideo.getChildAt(groupPo - fristPos);
180 | if (v != null) {
181 | RecyclerView rc_content = (RecyclerView) v.findViewById(R.id.rc_group_content);
182 | int fristPos1 = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findFirstVisibleItemPosition();
183 | int lastPos1 = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findLastVisibleItemPosition();
184 | if (childPo >= fristPos1 && childPo <= lastPos1) {//当上一项为可见项的时候
185 | View v1 = rc_content.getChildAt(childPo - fristPos1);
186 | v1.findViewById(R.id.imgV_select).setSelected(false);
187 | }
188 | }
189 |
190 | }
191 | } else if (mCurAdapter != null) {
192 | // mCurAdapter.notifyDataSetChanged();
193 | mCurAdapter.notifyItemChanged(childPo);
194 | }
195 |
196 | }
197 | groupPo = po;
198 | childPo = position;
199 | mCurAdapter = mAdapter;
200 | } else {
201 | if (item.is_select()) {
202 | view.findViewById(R.id.imgV_select).setSelected(false);
203 | mDataList.get(po).getmFileList().get(position).setIs_select(false);
204 | ((ChooseFileActivity) aty).removeFile(item.getId());
205 | } else {
206 | view.findViewById(R.id.imgV_select).setSelected(true);
207 | mDataList.get(po).getmFileList().get(position).setIs_select(true);
208 | ((ChooseFileActivity) aty).addFile(item);
209 | }
210 | }
211 |
212 | isChoose = true;
213 | mGroupAdapter.notifyDataSetChanged();
214 | }
215 |
216 | @Override
217 | public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
218 | return false;
219 | }
220 | });
221 |
222 |
223 | return mAdapter;
224 |
225 | }
226 | private Handler handler = new Handler() {
227 | @Override
228 | public void handleMessage(Message msg) {
229 | super.handleMessage(msg);
230 |
231 | mGroupAdapter.notifyDataSetChanged();
232 | }
233 | };
234 | private void setDataList( List files )
235 | {
236 | mDataList.clear();
237 | FileGroupInfo words=new FileGroupInfo("WORD");
238 | FileGroupInfo excels=new FileGroupInfo("EXCEL");
239 | FileGroupInfo padfs=new FileGroupInfo("PDF");
240 | FileGroupInfo ppts=new FileGroupInfo("PPT");
241 | FileGroupInfo other=new FileGroupInfo("OTHER");
242 | for (int i = 0; i 0) {
257 | mDataList.add(words);
258 | }
259 | if (excels.getmFileList().size()>0) {
260 | mDataList.add(excels);
261 | }
262 | if (padfs.getmFileList().size()>0) {
263 | mDataList.add(padfs);
264 | }
265 | if (ppts.getmFileList().size()>0) {
266 | mDataList.add(ppts);
267 | }
268 | if (other.getmFileList().size()>0) {
269 | mDataList.add(other);
270 | }
271 |
272 | }
273 | }
274 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/fragments/OtherFragment.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.View;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import choose.lm.com.fileselector.R;
14 | import choose.lm.com.fileselector.activitys.ChooseFileActivity;
15 | import choose.lm.com.fileselector.base.BaseFragment;
16 | import choose.lm.com.fileselector.base.MyApplication;
17 | import choose.lm.com.fileselector.base.recyclerview.CommonAdapter;
18 | import choose.lm.com.fileselector.base.recyclerview.MultiItemTypeAdapter;
19 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
20 | import choose.lm.com.fileselector.databinding.LibVideoFragmentBinding;
21 | import choose.lm.com.fileselector.model.FileGroupInfo;
22 | import choose.lm.com.fileselector.model.FileInfo;
23 | import choose.lm.com.fileselector.utils.DateUtil;
24 | import choose.lm.com.fileselector.utils.FileUtil;
25 | import choose.lm.com.fileselector.utils.LoadFiles;
26 |
27 | /**
28 | * Created by Administrator on 2016/11/28 0028.
29 | */
30 | public class OtherFragment extends BaseFragment {
31 |
32 | List mDataList = new ArrayList<>();
33 | private CommonAdapter mGroupAdapter;
34 |
35 | private boolean isChoose = false;
36 |
37 | /**
38 | * 单选模式 清楚状态
39 | */
40 | public void clearState() {
41 | if (isChoose) {
42 |
43 | for (int i = 0; i < mDataList.size(); i++) {
44 | for (int j = 0; j < mDataList.get(i).getmFileList().size(); j++) {
45 | mDataList.get(i).getmFileList().get(j).setIs_select(false);
46 | }
47 | }
48 | mGroupAdapter.notifyDataSetChanged();
49 | }
50 | }
51 |
52 | @Override
53 | public int getLayoutId() {
54 | return R.layout.lib_video_fragment;
55 | }
56 |
57 | @Override
58 | protected void initData() {
59 | super.initData();
60 |
61 | }
62 |
63 | @Override
64 | protected void initView(Bundle savedInstanceState) {
65 | super.initView(savedInstanceState);
66 | mGroupAdapter = new CommonAdapter(aty,R.layout.lib_item_file_group,mDataList) {
67 | @Override
68 | protected void convert(final ViewHolder helper, final FileGroupInfo item, final int position) {
69 | if (mDataList.get(position).is_choose()) {
70 | helper.setVisible(R.id.rc_group_content, true);
71 | helper.setSelected(R.id.img_choose, true);
72 | mDataList.get(position).setIs_choose(true);
73 | } else {
74 | helper.setVisible(R.id.rc_group_content, false);
75 | helper.setSelected(R.id.img_choose, false);
76 | mDataList.get(position).setIs_choose(false);
77 | }
78 | helper.setText(R.id.tv_group_name, item.getGroup_name());
79 | RecyclerView content = helper.getView(R.id.rc_group_content);
80 | content.setLayoutManager(new LinearLayoutManager(aty));
81 | content.setAdapter(getmAdapter(item.getmFileList(), position));
82 | helper.setOnClickListener(R.id.lly_choose, new View.OnClickListener() {
83 | @Override
84 | public void onClick(View v) {
85 | if (mDataList.get(position).is_choose()) {
86 | helper.setVisible(R.id.rc_group_content, false);
87 | helper.setSelected(R.id.img_choose, false);
88 | mDataList.get(position).setIs_choose(false);
89 | } else {
90 | helper.setSelected(R.id.img_choose, true);
91 | mDataList.get(position).setIs_choose(true);
92 | helper.setVisible(R.id.rc_group_content, true);
93 |
94 | }
95 |
96 | }
97 | });
98 |
99 | }
100 | };
101 | mBinding.rcVideo.setLayoutManager(new LinearLayoutManager(aty));
102 | mBinding.rcVideo.setAdapter(mGroupAdapter);
103 |
104 | loadData();
105 | }
106 |
107 | public void loadData()
108 | {
109 | if (MyApplication.getInstance().getContentResolver()!=null) {
110 | new Thread() {
111 | @Override
112 | public void run() {
113 | super.run();
114 | LoadFiles loadFiles = new LoadFiles();
115 | loadFiles.loadOtherFile(MyApplication.getInstance().getContentResolver());
116 | setDataList(loadFiles.getOtherFiles());
117 | handler.sendEmptyMessage(0);
118 | }
119 | }.start();
120 | }
121 | }
122 | private int groupPo = -1, childPo = -1;
123 | private CommonAdapter mCurAdapter;
124 |
125 | public CommonAdapter getmAdapter(List data, final int po) {
126 |
127 | final CommonAdapter mAdapter = new CommonAdapter(aty,R.layout.lib_item_video_fragment,data) {
128 | @Override
129 | protected void convert(ViewHolder helper, FileInfo item, int position) {
130 | if (FileInfo.FileType.RAR.equals(item.getFile_type())) {
131 | helper.setImageResource(R.id.img, R.drawable.ico_rar);
132 | } else if (FileInfo.FileType.TEXT.equals(item.getFile_type())) {
133 | helper.setImageResource(R.id.img, R.drawable.ico_txt);
134 | } else {
135 | helper.setImageResource(R.id.img, R.drawable.ico_other);
136 | }
137 | helper.setText(R.id.tv_time, DateUtil.getCommunityTime(item.getFile_modified_time()));
138 | helper.setText(R.id.tv_name, item.getFile_name());
139 | helper.setText(R.id.tv_size, FileUtil.bytes2kb(item.getFile_size()));
140 | if (item.is_select()) {
141 | helper.setSelected(R.id.imgV_select, true);
142 | helper.getConvertView().setSelected(true);
143 | } else {
144 | helper.setSelected(R.id.imgV_select, false);
145 | helper.getConvertView().setSelected(false);
146 | }
147 |
148 |
149 | }
150 | };
151 |
152 | mAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
153 | @Override
154 | public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
155 | FileInfo item = mDataList.get(po).getmFileList().get(position);
156 | if (!((ChooseFileActivity) aty).mIsMultiselect) {//单选
157 | ((ChooseFileActivity) aty).clearFile();
158 |
159 | if (item.is_select()) {
160 | view.findViewById(R.id.imgV_select).setSelected(false);
161 | mDataList.get(po).getmFileList().get(position).setIs_select(false);
162 | ((ChooseFileActivity) aty).removeFile(item.getId());
163 | } else {
164 | view.findViewById(R.id.imgV_select).setSelected(true);
165 | mDataList.get(po).getmFileList().get(position).setIs_select(true);
166 | ((ChooseFileActivity) aty).addFile(item);
167 | }
168 |
169 | if (groupPo != -1 && !(groupPo == po && childPo == position)) {
170 | mDataList.get(groupPo).getmFileList().get(childPo).setIs_select(false);
171 | if (groupPo == po) {
172 | int fristPos = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findFirstVisibleItemPosition();
173 | int lastPos = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findLastVisibleItemPosition();
174 | if (groupPo >= fristPos && lastPos <= lastPos) {//当上一项为可见项的时候
175 | View v = mBinding.rcVideo.getChildAt(groupPo - fristPos);
176 | if (v != null) {
177 | RecyclerView rc_content = (RecyclerView) v.findViewById(R.id.rc_group_content);
178 | int fristPos1 = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findFirstVisibleItemPosition();
179 | int lastPos1 = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findLastVisibleItemPosition();
180 | if (childPo >= fristPos1 && childPo <= lastPos1) {//当上一项为可见项的时候
181 | View v1 = rc_content.getChildAt(childPo - fristPos1);
182 | v1.findViewById(R.id.imgV_select).setSelected(false);
183 | }
184 | }
185 |
186 | }
187 | } else if (mCurAdapter != null) {
188 | mCurAdapter.notifyDataSetChanged();
189 | }
190 |
191 | }
192 | groupPo = po;
193 | childPo = position;
194 | mCurAdapter = mAdapter;
195 |
196 | } else {
197 | if (item.is_select()) {
198 | view.findViewById(R.id.imgV_select).setSelected(false);
199 | mDataList.get(po).getmFileList().get(position).setIs_select(false);
200 | ((ChooseFileActivity) aty).removeFile(item.getId());
201 | } else {
202 | view.findViewById(R.id.imgV_select).setSelected(true);
203 | mDataList.get(po).getmFileList().get(position).setIs_select(true);
204 | ((ChooseFileActivity) aty).addFile(item);
205 | }
206 | }
207 | isChoose = true;
208 | mAdapter.notifyDataSetChanged();
209 | }
210 |
211 | @Override
212 | public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
213 | return false;
214 | }
215 | });
216 |
217 |
218 |
219 | return mAdapter;
220 | }
221 |
222 | private void setDataList(List files) {
223 | mDataList.clear();
224 | FileGroupInfo rars = new FileGroupInfo("压缩文件");
225 | FileGroupInfo txts = new FileGroupInfo("电子书");
226 |
227 | for (int i = 0; i < files.size(); i++) {
228 | FileInfo item = files.get(i);
229 | if (FileInfo.FileType.RAR.equals(item.getFile_type())) {
230 | rars.addFile(item);
231 | } else if (FileInfo.FileType.TEXT.equals(item.getFile_type())) {
232 | txts.addFile(item);
233 | }
234 | }
235 | if (rars.getmFileList().size() > 0) {
236 | mDataList.add(rars);
237 | }
238 | if (txts.getmFileList().size() > 0) {
239 | mDataList.add(txts);
240 | }
241 | }
242 |
243 | private Handler handler = new Handler() {
244 | @Override
245 | public void handleMessage(Message msg) {
246 | super.handleMessage(msg);
247 | mGroupAdapter.notifyDataSetChanged();
248 |
249 | }
250 | };
251 | }
252 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/fragments/PhotoFragment.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.support.v7.widget.GridLayoutManager;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import choose.lm.com.fileselector.R;
12 | import choose.lm.com.fileselector.activitys.ChooseFileActivity;
13 | import choose.lm.com.fileselector.adapters.selectrecycleview.ChoosePhotoAdapter;
14 | import choose.lm.com.fileselector.adapters.selectrecycleview.SectionedSpanSizeLookup;
15 | import choose.lm.com.fileselector.base.BaseFragment;
16 | import choose.lm.com.fileselector.base.MyApplication;
17 | import choose.lm.com.fileselector.databinding.LibPhotoFragmentBinding;
18 | import choose.lm.com.fileselector.model.FileGroupInfo;
19 | import choose.lm.com.fileselector.model.FileInfo;
20 | import choose.lm.com.fileselector.utils.LoadFiles;
21 |
22 | /**
23 | * Created by Administrator on 2016/11/28 0028.
24 | */
25 | public class PhotoFragment extends BaseFragment {
26 |
27 | List mDataList = new ArrayList<>();
28 | private ChoosePhotoAdapter mGroupAdapter;
29 | @Override
30 | public int getLayoutId() {
31 | return R.layout.lib_photo_fragment;
32 | }
33 |
34 |
35 | private boolean isChoose = false;
36 |
37 | /**
38 | * 单选模式 清楚状态
39 | */
40 | public void clearState() {
41 | if (isChoose) {
42 | mGroupAdapter.clearState();
43 | }
44 | }
45 |
46 | @Override
47 | protected void initData() {
48 | super.initData();
49 | width = aty.getWindowManager().getDefaultDisplay().getWidth();
50 | }
51 |
52 | int width = 0;
53 |
54 | @Override
55 | protected void initView(Bundle savedInstanceState) {
56 | super.initView(savedInstanceState);
57 | mGroupAdapter=new ChoosePhotoAdapter(aty,((ChooseFileActivity)aty).mIsMultiselect);
58 | GridLayoutManager manager = new GridLayoutManager(aty,4);
59 | //设置header
60 | manager.setSpanSizeLookup(new SectionedSpanSizeLookup(mGroupAdapter, manager));
61 | mBinding.rcPhoto.setLayoutManager(manager);
62 | mBinding.rcPhoto.setAdapter(mGroupAdapter);
63 | mGroupAdapter.setOnItemClickListener(new ChoosePhotoAdapter.onItemClickListener() {
64 | @Override
65 | public void onGroupClick(int group) {
66 |
67 | }
68 |
69 | @Override
70 | public void onChildClick(int group, int child,boolean is_choose) {
71 | FileInfo item = mDataList.get(group).getmFileList().get(child);
72 | if (!((ChooseFileActivity) aty).mIsMultiselect) {//单选
73 | ((ChooseFileActivity) aty).clearFile();
74 | }
75 | if (!is_choose) {
76 | ((ChooseFileActivity) aty).removeFile(item.getId());
77 | } else {
78 | ((ChooseFileActivity) aty).addFile(item);
79 | }
80 | isChoose = true;
81 | }
82 | });
83 | loadData();
84 | }
85 |
86 |
87 | public void loadData()
88 | {
89 | if (MyApplication.getInstance().getContentResolver()!=null) {
90 | new Thread() {
91 | @Override
92 | public void run() {
93 | super.run();
94 | LoadFiles loadFiles = new LoadFiles();
95 | loadFiles.loadImages(MyApplication.getInstance().getContentResolver());
96 | setDataList(loadFiles.getImages());
97 | handler.sendEmptyMessage(0);
98 | }
99 | }.start();
100 | }
101 | }
102 |
103 |
104 | public String getFolder(String folder) {
105 | if (folder.contains("ylwj_expert/image/")) {
106 | return "已下载的图片";
107 | }
108 | if (folder.contains("Camera/")) {
109 | return "相册";
110 | }
111 | String[] split = folder.split("/");
112 | if (split.length >= 2) {
113 | return split[split.length - 2];
114 | }
115 | return "";
116 | }
117 |
118 | private void setDataList(List files) {
119 | mDataList.clear();
120 | List folders = new ArrayList<>();
121 | for (int i = 0; i < files.size(); i++) {
122 | String folder = getFolder(files.get(i).getFile_path());
123 | if (!folders.contains(folder)) {
124 | if ("相册".equals(folder)) {
125 | folders.add(0, folder);
126 | mDataList.add(0, new FileGroupInfo(folder));
127 | } else {
128 | folders.add(folder);
129 | mDataList.add(new FileGroupInfo(folder));
130 | }
131 | }
132 | }
133 | for (int i = 0; i < files.size(); i++) {
134 | String folder = getFolder(files.get(i).getFile_path());
135 | for (int j = 0; j < folders.size(); j++) {
136 | if (folders.get(j).equals(folder)&&!files.get(i).getFile_path().contains(".gif")) {
137 | mDataList.get(j).getmFileList().add(files.get(i));
138 | }
139 | }
140 | }
141 |
142 | }
143 |
144 |
145 | private Handler handler = new Handler() {
146 | @Override
147 | public void handleMessage(Message msg) {
148 | super.handleMessage(msg);
149 | mGroupAdapter.setData(mDataList);
150 | }
151 | };
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/fragments/VideoFragment.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.View;
9 |
10 | import java.io.File;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import choose.lm.com.fileselector.R;
15 | import choose.lm.com.fileselector.activitys.ChooseFileActivity;
16 | import choose.lm.com.fileselector.base.BaseFragment;
17 | import choose.lm.com.fileselector.base.MyApplication;
18 | import choose.lm.com.fileselector.base.recyclerview.CommonAdapter;
19 | import choose.lm.com.fileselector.base.recyclerview.MultiItemTypeAdapter;
20 | import choose.lm.com.fileselector.base.recyclerview.base.ViewHolder;
21 | import choose.lm.com.fileselector.databinding.LibVideoFragmentBinding;
22 | import choose.lm.com.fileselector.model.FileGroupInfo;
23 | import choose.lm.com.fileselector.model.FileInfo;
24 | import choose.lm.com.fileselector.utils.DateUtil;
25 | import choose.lm.com.fileselector.utils.FileUtil;
26 | import choose.lm.com.fileselector.utils.LoadFiles;
27 |
28 | /**
29 | * Created by Administrator on 2016/11/28 0028.
30 | */
31 | public class VideoFragment extends BaseFragment {
32 |
33 | List mDataList = new ArrayList<>();
34 | private CommonAdapter mGroupAdapter;
35 |
36 |
37 | @Override
38 | public int getLayoutId() {
39 | return R.layout.lib_video_fragment;
40 | }
41 | private boolean isChoose=false;
42 | /**
43 | * 单选模式 清楚状态
44 | */
45 | public void clearState() {
46 | if (isChoose) {
47 | for (int i = 0; i < mDataList.size(); i++) {
48 | for (int j = 0; j < mDataList.get(i).getmFileList().size(); j++) {
49 | mDataList.get(i).getmFileList().get(j).setIs_select(false);
50 | }
51 | }
52 | mGroupAdapter.notifyDataSetChanged();
53 |
54 | }
55 | }
56 | @Override
57 | protected void initData() {
58 | super.initData();
59 |
60 | }
61 |
62 | @Override
63 | protected void initView(Bundle savedInstanceState) {
64 | super.initView(savedInstanceState);
65 |
66 | mGroupAdapter = new CommonAdapter(aty,R.layout.lib_item_file_group,mDataList) {
67 | @Override
68 | protected void convert(final ViewHolder helper, final FileGroupInfo item, final int position) {
69 |
70 | if (mDataList.get(position).is_choose()) {
71 | helper.setVisible(R.id.rc_group_content, true);
72 | helper.setSelected(R.id.img_choose, true);
73 | mDataList.get(position).setIs_choose(true);
74 | } else {
75 | helper.setVisible(R.id.rc_group_content, false);
76 | helper.setSelected(R.id.img_choose, false);
77 | mDataList.get(position).setIs_choose(false);
78 | }
79 | helper.setText(R.id.tv_group_name, item.getGroup_name());
80 | RecyclerView content = helper.getView(R.id.rc_group_content);
81 | content.setLayoutManager(new LinearLayoutManager(aty));
82 | content.setAdapter(getmAdapter(item.getmFileList(), position));
83 |
84 |
85 | helper.setOnClickListener(R.id.lly_choose, new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | if (mDataList.get(position).is_choose()) {
89 | helper.setVisible(R.id.rc_group_content, false);
90 | helper.setSelected(R.id.img_choose, false);
91 | mDataList.get(position).setIs_choose(false);
92 | } else {
93 | helper.setVisible(R.id.rc_group_content, true);
94 | helper.setSelected(R.id.img_choose, true);
95 | mDataList.get(position).setIs_choose(true);
96 | }
97 | }
98 | });
99 |
100 | }
101 | };
102 | mBinding.rcVideo.setLayoutManager(new LinearLayoutManager(aty));
103 | mBinding.rcVideo.setAdapter(mGroupAdapter);
104 | loadData();
105 | }
106 |
107 | public void loadData()
108 | {
109 | if (MyApplication.getInstance().getContentResolver()!=null) {
110 | new Thread() {
111 | @Override
112 | public void run() {
113 | super.run();
114 | LoadFiles loadFiles = new LoadFiles();
115 | loadFiles.loadVideo(MyApplication.getInstance().getContentResolver());
116 | loadFiles.loadMP3(MyApplication.getInstance().getContentResolver());
117 | setDataList(loadFiles.getVideos());
118 | handler.sendEmptyMessage(0);
119 | }
120 | }.start();
121 | }
122 | }
123 | private int groupPo = -1, childPo = -1;
124 | private CommonAdapter mCurAdapter;
125 | public CommonAdapter getmAdapter(List data, final int po) {
126 | final CommonAdapter mAdapter = new CommonAdapter(aty,R.layout.lib_item_video_fragment,data) {
127 | @Override
128 | protected void convert(ViewHolder helper, FileInfo item, int position) {
129 | if (item.is_thumnbail()) {
130 | helper.setImageFile(R.id.img, new File(item.getFile_path()), 0.7f, R.drawable.img_preloading);
131 | } else {
132 | helper.setImageResource(R.id.img, R.drawable.ico_mp3);
133 | }
134 | helper.setText(R.id.tv_time, DateUtil.getCommunityTime(item.getFile_modified_time()));
135 | helper.setText(R.id.tv_name, item.getFile_name());
136 | helper.setText(R.id.tv_size, FileUtil.bytes2kb(item.getFile_size()));
137 |
138 | if (mDataList.get(po).getmFileList().get(position).is_select()) {
139 | helper.setSelected(R.id.imgV_select, true);
140 | helper.getConvertView().setSelected(true);
141 | } else {
142 | helper.setSelected(R.id.imgV_select, false);
143 | helper.getConvertView().setSelected(false);
144 | }
145 |
146 | }
147 |
148 |
149 | };
150 | mAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
151 | @Override
152 | public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
153 | FileInfo item = mDataList.get(po).getmFileList().get(position);
154 | if (!((ChooseFileActivity) aty).mIsMultiselect) {//单选
155 | ((ChooseFileActivity) aty).clearFile();
156 |
157 | if (item.is_select()) {
158 | view.findViewById(R.id.imgV_select).setSelected(false);
159 | mDataList.get(po).getmFileList().get(position).setIs_select(false);
160 | ((ChooseFileActivity) aty).removeFile(item.getId());
161 | } else {
162 | view.findViewById(R.id.imgV_select).setSelected(true);
163 | mDataList.get(po).getmFileList().get(position).setIs_select(true);
164 | ((ChooseFileActivity) aty).addFile(item);
165 | }
166 |
167 | if (groupPo != -1 && !(groupPo == po && childPo == position)) {
168 | mDataList.get(groupPo).getmFileList().get(childPo).setIs_select(false);
169 | if (groupPo == po) {
170 | int fristPos = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findFirstVisibleItemPosition();
171 | int lastPos = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findLastVisibleItemPosition();
172 | if (groupPo >= fristPos && lastPos <= lastPos) {//当上一项为可见项的时候
173 | View v = mBinding.rcVideo.getChildAt(groupPo - fristPos);
174 | if (v != null) {
175 | RecyclerView rc_content = (RecyclerView) v.findViewById(R.id.rc_group_content);
176 | int fristPos1 = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findFirstVisibleItemPosition();
177 | int lastPos1 = ((LinearLayoutManager) mBinding.rcVideo.getLayoutManager()).findLastVisibleItemPosition();
178 | if (childPo >= fristPos1 && childPo <= lastPos1) {//当上一项为可见项的时候
179 | View v1 = rc_content.getChildAt(childPo - fristPos1);
180 | v1.findViewById(R.id.imgV_select).setSelected(false);
181 | }
182 | }
183 |
184 | }
185 | } else if (mCurAdapter != null) {
186 | mCurAdapter.notifyDataSetChanged();
187 | }
188 |
189 | }
190 | groupPo = po;
191 | childPo = position;
192 | mCurAdapter = mAdapter;
193 |
194 | } else {
195 | if (item.is_select()) {
196 | view.findViewById(R.id.imgV_select).setSelected(false);
197 | mDataList.get(po).getmFileList().get(position).setIs_select(false);
198 | ((ChooseFileActivity) aty).removeFile(item.getId());
199 | } else {
200 | view.findViewById(R.id.imgV_select).setSelected(true);
201 | mDataList.get(po).getmFileList().get(position).setIs_select(true);
202 | ((ChooseFileActivity) aty).addFile(item);
203 | }
204 | }
205 | isChoose = true;
206 | mAdapter.notifyDataSetChanged();
207 | }
208 |
209 | @Override
210 | public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
211 | return false;
212 | }
213 | });
214 |
215 |
216 | return mAdapter;
217 | }
218 |
219 | private Handler handler = new Handler() {
220 | @Override
221 | public void handleMessage(Message msg) {
222 | super.handleMessage(msg);
223 | mGroupAdapter.notifyDataSetChanged();
224 | }
225 | };
226 |
227 |
228 | public String getFolder(String folder) {
229 | if (folder.contains("ylwj_expert/voice/")) {
230 | return "已下载的影音";
231 | }
232 | String[] split = folder.split("/");
233 | if (split.length >= 2) {
234 | return split[split.length - 2];
235 | }
236 | return "";
237 | }
238 |
239 | private void setDataList(List files) {
240 | mDataList.clear();
241 | List folders = new ArrayList<>();
242 | for (int i = 0; i < files.size(); i++) {
243 | String folder = getFolder(files.get(i).getFile_path());
244 | if (!folders.contains(folder)) {
245 | if ("已下载的影音".equals(folder)) {
246 | folders.add(0,folder);
247 | mDataList.add(0,new FileGroupInfo(folder));
248 | } else {
249 | folders.add(folder);
250 | mDataList.add(new FileGroupInfo(folder));
251 | }
252 |
253 | }
254 | }
255 | for (int i = 0; i < files.size(); i++) {
256 | String folder = getFolder(files.get(i).getFile_path());
257 | for (int j = 0; j < folders.size(); j++) {
258 | if (folders.get(j).equals(folder)) {
259 | mDataList.get(j).getmFileList().add(files.get(i));
260 | }
261 | }
262 | }
263 | }
264 |
265 | }
266 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/model/FileGroupInfo.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.model;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by Administrator on 2016/12/2 0002.
8 | */
9 | public class FileGroupInfo {
10 | private String group_name;
11 | private boolean is_choose=false;
12 | private List mFileList=new ArrayList<>();
13 |
14 | public FileGroupInfo(String group_name) {
15 | this.group_name = group_name;
16 | }
17 |
18 | public String getGroup_name() {
19 | return group_name;
20 | }
21 |
22 | public void setGroup_name(String group_name) {
23 | this.group_name = group_name;
24 | }
25 |
26 | public List getmFileList() {
27 | return mFileList;
28 | }
29 | public void addFile(FileInfo info)
30 | {
31 | mFileList.add(info);
32 | }
33 |
34 | public boolean is_choose() {
35 | return is_choose;
36 | }
37 |
38 | public void setIs_choose(boolean is_choose) {
39 | this.is_choose = is_choose;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/model/FileInfo.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.model;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by Administrator on 2016/11/28 0028.
8 | */
9 | public class FileInfo implements Parcelable {
10 | public interface FileType {//文件类型
11 | String VIDEO = "video";
12 | String IMAGE = "image";
13 | String RAR = "rar";
14 | String EXCEL = "excel";
15 | String PDF = "pdf";
16 | String PPT = "ppt";
17 | String WORD = "word";
18 | String MP3 = "mp3";
19 | String TEXT = "txt";
20 | }
21 | private int file_id;
22 | private int id;
23 | private String file_name;
24 | private String file_path;
25 | private String file_type;
26 | private long file_size;
27 | private String file_thumnbail;
28 | private long file_modified_time;
29 | private boolean is_thumnbail;
30 | private boolean is_select=false;
31 |
32 | public FileInfo(int id, int file_id, String file_name, String file_path, long file_size, long file_modified_time, boolean is_thumnbail, String file_type) {
33 | this.id = id;
34 | this.file_id = file_id;
35 | this.file_name = file_name;
36 | this.file_path = file_path;
37 | this.file_size = file_size;
38 | this.file_modified_time = file_modified_time;
39 | this.is_thumnbail = is_thumnbail;
40 | this.file_type = file_type;
41 | }
42 |
43 | public int getId() {
44 | return id;
45 | }
46 |
47 | public void setId(int id) {
48 | this.id = id;
49 | }
50 |
51 | public boolean is_select() {
52 | return is_select;
53 | }
54 |
55 | public void setIs_select(boolean is_select) {
56 | this.is_select = is_select;
57 | }
58 |
59 | public int getFile_id() {
60 | return file_id;
61 | }
62 |
63 | public void setFile_id(int file_id) {
64 | this.file_id = file_id;
65 | }
66 |
67 | public boolean is_thumnbail() {
68 | return is_thumnbail;
69 | }
70 |
71 | public void setIs_thumnbail(boolean is_thumnbail) {
72 | this.is_thumnbail = is_thumnbail;
73 | }
74 |
75 | public String getFile_name() {
76 | return file_name;
77 | }
78 |
79 | public void setFile_name(String file_name) {
80 | this.file_name = file_name;
81 | }
82 |
83 | public String getFile_path() {
84 | return file_path;
85 | }
86 |
87 | public void setFile_path(String file_path) {
88 | this.file_path = file_path;
89 | }
90 |
91 | public long getFile_size() {
92 | return file_size;
93 | }
94 |
95 | public void setFile_size(long file_size) {
96 | this.file_size = file_size;
97 | }
98 |
99 | public String getFile_thumnbail() {
100 | return file_thumnbail;
101 | }
102 |
103 | public void setFile_thumnbail(String file_thumnbail) {
104 | this.file_thumnbail = file_thumnbail;
105 | }
106 |
107 | public long getFile_modified_time() {
108 | return file_modified_time;
109 | }
110 |
111 | public void setFile_modified_time(long file_modified_time) {
112 | this.file_modified_time = file_modified_time;
113 | }
114 |
115 | public String getFile_type() {
116 | return file_type;
117 | }
118 |
119 | public void setFile_type(String file_type) {
120 | this.file_type = file_type;
121 | }
122 |
123 | @Override
124 | public int describeContents() {
125 | return 0;
126 | }
127 |
128 | @Override
129 | public void writeToParcel(Parcel dest, int flags) {
130 | dest.writeInt(this.file_id);
131 | dest.writeInt(this.id);
132 | dest.writeString(this.file_name);
133 | dest.writeString(this.file_path);
134 | dest.writeString(this.file_type);
135 | dest.writeLong(this.file_size);
136 | dest.writeString(this.file_thumnbail);
137 | dest.writeLong(this.file_modified_time);
138 | dest.writeByte(this.is_thumnbail ? (byte) 1 : (byte) 0);
139 | dest.writeByte(this.is_select ? (byte) 1 : (byte) 0);
140 | }
141 |
142 | protected FileInfo(Parcel in) {
143 | this.file_id = in.readInt();
144 | this.id = in.readInt();
145 | this.file_name = in.readString();
146 | this.file_path = in.readString();
147 | this.file_type = in.readString();
148 | this.file_size = in.readLong();
149 | this.file_thumnbail = in.readString();
150 | this.file_modified_time = in.readLong();
151 | this.is_thumnbail = in.readByte() != 0;
152 | this.is_select = in.readByte() != 0;
153 | }
154 |
155 | public static final Creator CREATOR = new Creator() {
156 | @Override
157 | public FileInfo createFromParcel(Parcel source) {
158 | return new FileInfo(source);
159 | }
160 |
161 | @Override
162 | public FileInfo[] newArray(int size) {
163 | return new FileInfo[size];
164 | }
165 | };
166 | }
167 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/utils/DateUtil.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.utils;
2 |
3 | import java.text.DateFormat;
4 | import java.text.ParseException;
5 | import java.text.SimpleDateFormat;
6 | import java.util.Calendar;
7 | import java.util.Date;
8 | import java.util.GregorianCalendar;
9 | import java.util.Locale;
10 | import java.util.TimeZone;
11 |
12 | /**
13 | * Created by wjq on 2016/9/6.
14 | * 时间转换
15 | */
16 | public class DateUtil {
17 | public static final TimeZone tz = TimeZone.getTimeZone("GMT+8:00");
18 | public static final SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy-MM-dd");
19 |
20 | private static final long ONEDAY = 86400000;
21 | public static final int SHOW_TYPE_SIMPLE = 0;
22 | public static final int SHOW_TYPE_COMPLEX = 1;
23 | public static final int SHOW_TYPE_ALL = 2;
24 | public static final int SHOW_TYPE_CALL_LOG = 3;
25 | public static final int SHOW_TYPE_CALL_DETAIL = 4;
26 |
27 | /**
28 | * 获取当前当天日期的毫秒数 2012-03-21的毫秒数
29 | *
30 | * @return
31 | */
32 | public static long getCurrentDayTime() {
33 | Date d = new Date(System.currentTimeMillis());
34 | String formatDate = yearFormat.format(d);
35 | try {
36 | return (yearFormat.parse(formatDate)).getTime();
37 | } catch (ParseException e) {
38 | e.printStackTrace();
39 | }
40 | return 0;
41 | }
42 |
43 | public static String formatDate(int year, int month, int day) {
44 | Date d = new Date(year - 1900, month, day);
45 | return yearFormat.format(d);
46 | }
47 | public static String getCommunityTime(long time) {
48 | SimpleDateFormat df2 = new SimpleDateFormat("MM月dd日 HH:mm");
49 | return df2.format(time);
50 |
51 | }
52 | public static long getDateMills(int year, int month, int day) {
53 | //Date d = new Date(year, month, day);
54 | // 1960 4 22
55 | Calendar calendar = Calendar.getInstance();
56 | calendar.set(year, month, day);
57 | TimeZone tz = TimeZone.getTimeZone("GMT");
58 | calendar.setTimeZone(tz);
59 | return calendar.getTimeInMillis();
60 | }
61 |
62 | /**
63 | * 根据用户生日计算年龄
64 | */
65 | public static String getAgeByBirthday(Date birthday) {
66 | String suishu="";
67 | Calendar cal = Calendar.getInstance();
68 | if (cal.before(birthday)) {
69 | throw new IllegalArgumentException(
70 | "The birthDay is before Now.It's unbelievable!");
71 | }
72 | int yearNow = cal.get(Calendar.YEAR);
73 | int monthNow = cal.get(Calendar.MONTH) + 1;
74 | int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
75 | cal.setTime(birthday);
76 | int yearBirth = cal.get(Calendar.YEAR);
77 | int monthBirth = cal.get(Calendar.MONTH) + 1;
78 | int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
79 | int age = yearNow - yearBirth;
80 | if(age==0){
81 | int month=monthNow-monthBirth;
82 | if(month==0){
83 | month=1;
84 | }
85 | suishu=month+"个月";
86 | }else {
87 | if (monthNow <= monthBirth) {
88 | if (monthNow == monthBirth) {
89 | // monthNow==monthBirth
90 | if (dayOfMonthNow < dayOfMonthBirth) {
91 | age--;
92 | }
93 | } else {
94 | // monthNow>monthBirth
95 | age--;
96 | }
97 | }
98 | suishu=age+"岁";
99 | }
100 | return suishu;
101 | }
102 |
103 |
104 | public static String getDateString(long time){
105 | String nowTime="";
106 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
107 | Date date = new Date(time);
108 | String msgTime=formatter.format(date);
109 | long currentTime= System.currentTimeMillis();
110 |
111 | long betweenDay=(currentTime-time)/(1000*3600*24);
112 | if(betweenDay>1){
113 | nowTime=msgTime;
114 | }else if(betweenDay==1){
115 | nowTime="昨天 "+msgTime.substring(10,msgTime.length());
116 | }else{
117 | nowTime=msgTime.substring(10,msgTime.length());
118 | }
119 | return nowTime;
120 | }
121 |
122 | public static String getDateString(long time, int type) {
123 | Calendar c = Calendar.getInstance();
124 | c = Calendar.getInstance(tz);
125 | c.setTimeInMillis(time);
126 | long currentTime = System.currentTimeMillis();
127 | Calendar current_c = Calendar.getInstance();
128 | current_c = Calendar.getInstance(tz);
129 | current_c.setTimeInMillis(currentTime);
130 |
131 | int currentYear = current_c.get(Calendar.YEAR);
132 | int y = c.get(Calendar.YEAR);
133 | int m = c.get(Calendar.MONTH) + 1;
134 | int d = c.get(Calendar.DAY_OF_MONTH);
135 | int hour = c.get(Calendar.HOUR_OF_DAY);
136 | int minute = c.get(Calendar.MINUTE);
137 | int second = c.get(Calendar.SECOND);
138 | long t = currentTime - time;
139 | long t2 = currentTime - getCurrentDayTime();
140 | String dateStr = "";
141 | if (t < t2 && t > 0) {
142 | if (type == SHOW_TYPE_SIMPLE) {
143 | dateStr = (hour < 10 ? "0" + hour : hour) + ":"
144 | + (minute < 10 ? "0" + minute : minute);
145 | } else if (type == SHOW_TYPE_COMPLEX) {
146 | dateStr = "今天 " + (hour < 10 ? "0" + hour : hour) + ":"
147 | + (minute < 10 ? "0" + minute : minute);
148 | } else if (type == SHOW_TYPE_CALL_LOG) {
149 | dateStr = "今天 " + (hour < 10 ? "0" + hour : hour) + ":"
150 | + (minute < 10 ? "0" + minute : minute);
151 | } else if (type == SHOW_TYPE_CALL_DETAIL) {
152 | dateStr = "今天 ";
153 | }else {
154 | dateStr = (hour < 10 ? "0" + hour : hour) + ":"
155 | + (minute < 10 ? "0" + minute : minute) + ":"
156 | + (second < 10 ? "0" + second : second);
157 | }
158 | } else if (t < (t2 + ONEDAY) && t > 0) {
159 | if (type == SHOW_TYPE_SIMPLE || type == SHOW_TYPE_CALL_DETAIL) {
160 | dateStr = "昨天 ";
161 | } else if (type == SHOW_TYPE_COMPLEX ) {
162 | dateStr = "昨天 " + (hour < 10 ? "0" + hour : hour) + ":"
163 | + (minute < 10 ? "0" + minute : minute);
164 | } else if (type == SHOW_TYPE_CALL_LOG) {
165 | dateStr = "昨天 " + (hour < 10 ? "0" + hour : hour) + ":"
166 | + (minute < 10 ? "0" + minute : minute);
167 | } else {
168 | dateStr = "昨天 " + (hour < 10 ? "0" + hour : hour) + ":"
169 | + (minute < 10 ? "0" + minute : minute) + ":"
170 | + (second < 10 ? "0" + second : second);
171 | }
172 | } else if (y == currentYear) {
173 | if (type == SHOW_TYPE_SIMPLE) {
174 | dateStr = (m < 10 ? "0" + m : m) + "/" + (d < 10 ? "0" + d : d);
175 | } else if (type == SHOW_TYPE_COMPLEX) {
176 | dateStr = (m < 10 ? "0" + m : m) + "月" + (d < 10 ? "0" + d : d)
177 | + "日";
178 | } else if (type == SHOW_TYPE_CALL_LOG || type == SHOW_TYPE_COMPLEX) {
179 | dateStr = (m < 10 ? "0" + m : m) + /* 月 */"/"
180 | + (d < 10 ? "0" + d : d) + /* 日 */" "
181 | + (hour < 10 ? "0" + hour : hour) + ":"
182 | + (minute < 10 ? "0" + minute : minute);
183 | } else if (type == SHOW_TYPE_CALL_DETAIL) {
184 | dateStr = y + "/" + (m < 10 ? "0" + m : m) + "/"
185 | + (d < 10 ? "0" + d : d);
186 | } else {
187 | dateStr = (m < 10 ? "0" + m : m) + "月" + (d < 10 ? "0" + d : d)
188 | + "日 " + (hour < 10 ? "0" + hour : hour) + ":"
189 | + (minute < 10 ? "0" + minute : minute) + ":"
190 | + (second < 10 ? "0" + second : second);
191 | }
192 | } else {
193 | if (type == SHOW_TYPE_SIMPLE) {
194 | dateStr = y + "/" + (m < 10 ? "0" + m : m) + "/"
195 | + (d < 10 ? "0" + d : d);
196 | } else if (type == SHOW_TYPE_COMPLEX ) {
197 | dateStr = y + "年" + (m < 10 ? "0" + m : m) + "月"
198 | + (d < 10 ? "0" + d : d) + "日";
199 | } else if (type == SHOW_TYPE_CALL_LOG || type == SHOW_TYPE_COMPLEX) {
200 | dateStr = y + /* 年 */"/" + (m < 10 ? "0" + m : m) + /* 月 */"/"
201 | + (d < 10 ? "0" + d : d) + /* 日 */" "/*
202 | * + (hour < 10
203 | * ? "0" + hour
204 | * : hour) + ":"
205 | * + (minute <
206 | * 10 ? "0" +
207 | * minute :
208 | * minute)
209 | */;
210 | } else if (type == SHOW_TYPE_CALL_DETAIL) {
211 | dateStr = y + "/" + (m < 10 ? "0" + m : m) + "/"
212 | + (d < 10 ? "0" + d : d);
213 | } else {
214 | dateStr = y + "年" + (m < 10 ? "0" + m : m) + "月"
215 | + (d < 10 ? "0" + d : d) + "日 "
216 | + (hour < 10 ? "0" + hour : hour) + ":"
217 | + (minute < 10 ? "0" + minute : minute) + ":"
218 | + (second < 10 ? "0" + second : second);
219 | }
220 | }
221 | return dateStr;
222 | }
223 |
224 | /**
225 | *
226 | * @return
227 | */
228 | public static long getCurrentTime() {
229 | return System.currentTimeMillis() / 1000;
230 | }
231 |
232 | public static long getActiveTimelong(String result) {
233 | try {
234 | Date parse = yearFormat.parse(result);
235 | return parse.getTime();
236 | } catch (ParseException e) {
237 | e.printStackTrace();
238 | }
239 | return System.currentTimeMillis();
240 | }
241 |
242 | public static String getDefaultFormat() {
243 | return getDateFormat(sequenceFormat);
244 | }
245 |
246 | public static String getDateFormat(DateFormat df) {
247 | return getDateFormat(System.currentTimeMillis(), df);
248 | }
249 |
250 | public static String getDateFormat(long time, DateFormat df) {
251 | Date d = new Date(time);
252 | return df.format(d);
253 | }
254 | public static final SimpleDateFormat sequenceFormat = new SimpleDateFormat(
255 | "yyyyMMddHHmmss");
256 |
257 | public static long getMilliSeconds(String reqtime){
258 | try {
259 | long time = DateUtil.sequenceFormat.parse(reqtime).getTime();
260 | return time;
261 | } catch (ParseException e) {
262 | e.printStackTrace();
263 | }
264 | return 0;
265 | }
266 |
267 | public static String toGMTString(long milliseconds) {
268 | SimpleDateFormat sdf = new SimpleDateFormat("d MMM y HH:mm:ss 'GMT'", Locale.US);
269 | TimeZone gmtZone = TimeZone.getTimeZone("GMT");
270 | sdf.setTimeZone(gmtZone);
271 | GregorianCalendar gc = new GregorianCalendar(gmtZone);
272 | gc.setTimeInMillis(milliseconds);
273 | return sdf.format(new Date(milliseconds));
274 | }
275 | }
276 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/utils/FileUtil.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.utils;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.net.Uri;
6 | import android.os.Environment;
7 | import android.util.Base64;
8 |
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.File;
11 | import java.io.FileInputStream;
12 | import java.math.BigDecimal;
13 | import java.text.DecimalFormat;
14 |
15 | /**
16 | * 文件与流处理工具类
17 | *
18 | * Created by xw on 2016-8-1.
19 | */
20 | public class FileUtil
21 | {
22 |
23 | public static final String IMESSAGE_VOICE = getExternalStorePath() + "/ylwj_expert/voice";
24 | public static final String IMESSAGE_IMAGE = getExternalStorePath() + "/ylwj_expert/image";
25 | public static final String IMESSAGE_FILE = getExternalStorePath() + "/ylwj_expert/file";
26 | public static final String IMESSAGE_MOVES = getExternalStorePath() + "/ylwj_expert/moves";
27 |
28 | /**
29 | * 初始化应用文件夹目录
30 | */
31 | public static void initFileAccess() {
32 |
33 | File imessageDir = new File(IMESSAGE_VOICE);
34 | if (!imessageDir.exists()) {
35 | imessageDir.mkdir();
36 | }
37 |
38 | File imageDir = new File(IMESSAGE_IMAGE);
39 | if (!imageDir.exists()) {
40 | imageDir.mkdir();
41 | }
42 | File movesDir = new File(IMESSAGE_MOVES);
43 | if (! movesDir.exists()) {
44 | movesDir.mkdirs();
45 | }
46 |
47 | }
48 |
49 | /**
50 | * 判断文件是否存在
51 | *
52 | * @param filePath 文件路径
53 | * @return 是否存在
54 | */
55 | public static boolean fileIsExists(String filePath)
56 | {
57 | try
58 | {
59 | File f = new File(filePath);
60 | if (!f.exists())
61 | {
62 | return false;
63 | }
64 | } catch (Exception e)
65 | {
66 | return false;
67 | }
68 | return true;
69 | }
70 |
71 | /**
72 | * 获取bitmap
73 | *
74 | * @param filePath
75 | * @return
76 | */
77 | public static Bitmap getBitmapByPath(String filePath)
78 | {
79 | return getBitmapByPath(filePath, null);
80 | }
81 |
82 | /**
83 | * 获取突变通过Path
84 | *
85 | * @param filePath
86 | * @param opts
87 | * @return
88 | */
89 | public static Bitmap getBitmapByPath(String filePath,
90 | BitmapFactory.Options opts)
91 | {
92 | FileInputStream fis = null;
93 | Bitmap bitmap = null;
94 | try
95 | {
96 | bitmap = BitmapFactory.decodeFile(filePath, opts);
97 | } catch (OutOfMemoryError e)
98 | {
99 | e.printStackTrace();
100 | } finally
101 | {
102 | try
103 | {
104 | fis.close();
105 | } catch (Exception e)
106 | {
107 | }
108 | }
109 | return bitmap;
110 | }
111 |
112 | public static String path2StrByBase64(String path)
113 | {
114 | Bitmap bit = getBitmapByPath(path);
115 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
116 | bit.compress(Bitmap.CompressFormat.JPEG, 40, bos);//参数100表示不压缩
117 | byte[] bytes = bos.toByteArray();
118 | return Base64.encodeToString(bytes, Base64.DEFAULT);
119 | }
120 |
121 | /**
122 | * 图片转为base64
123 | * @param path 图片路径
124 | * @param isCompress 是否压缩
125 | * @return
126 | */
127 | public static String path2StrByBase64(String path, boolean isCompress)
128 | {
129 | Bitmap bit = getBitmapByPath(path);
130 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
131 | if(isCompress) {
132 | bit.compress(Bitmap.CompressFormat.JPEG, 40, bos);
133 | }else{
134 | bit.compress(Bitmap.CompressFormat.JPEG, 100, bos);//参数100表示不压缩
135 | }
136 | byte[] bytes = bos.toByteArray();
137 | return Base64.encodeToString(bytes, Base64.DEFAULT);
138 | }
139 |
140 |
141 | /**
142 | * 图片转为base64
143 | * @param bit 图片
144 | * @param isCompress 是否压缩
145 | * @return
146 | */
147 | public static String path2StrByBase64(Bitmap bit, boolean isCompress)
148 | {
149 |
150 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
151 | if(isCompress) {
152 | bit.compress(Bitmap.CompressFormat.JPEG, 40, bos);
153 | }else{
154 | bit.compress(Bitmap.CompressFormat.JPEG, 100, bos);//参数100表示不压缩
155 | }
156 | byte[] bytes = bos.toByteArray();
157 | return Base64.encodeToString(bytes, Base64.DEFAULT);
158 | }
159 |
160 |
161 | /**
162 | * 将文件转成base64 字符串
163 | * @param path 文件路径
164 | * @return
165 | * @throws Exception
166 | */
167 | public static String encodeBase64File(String path) throws Exception {
168 | File file = new File(path);
169 | FileInputStream inputFile = new FileInputStream(file);
170 | byte[] buffer = new byte[(int)file.length()];
171 | inputFile.read(buffer);
172 | inputFile.close();
173 | return Base64.encodeToString(buffer, Base64.DEFAULT);
174 | }
175 |
176 | /**
177 | * 是否有外存卡
178 | * @return
179 | */
180 | public static boolean isExistExternalStore() {
181 | if (Environment.getExternalStorageState().equals(
182 | Environment.MEDIA_MOUNTED)) {
183 | return true;
184 | } else {
185 | return false;
186 | }
187 | }
188 |
189 | /**
190 | * 外置存储卡的路径
191 | * @return
192 | */
193 | public static String getExternalStorePath() {
194 | if (isExistExternalStore()) {
195 | return Environment.getExternalStorageDirectory().getAbsolutePath();
196 | }
197 | return null;
198 | }
199 |
200 |
201 | /**
202 | * 获取语音文件存储目录
203 | * @return
204 | */
205 | public static File getVoicePathName() {
206 | if (!isExistExternalStore()) {
207 |
208 | return null;
209 | }
210 |
211 | File directory = new File(IMESSAGE_VOICE);
212 | if (!directory.exists() && !directory.mkdirs()) {
213 | return null;
214 | }
215 |
216 | return directory;
217 | }
218 |
219 | public static String getFileNameFromUrl(String url){
220 | if ((url != null) && (url.length() > 0)) {
221 | int dot = url.lastIndexOf("/");
222 | if ((dot > -1) && (dot < (url.length() - 1))) {
223 | return url.substring(dot + 1);
224 | }
225 | }
226 | return "";
227 | }
228 |
229 | public static String getFileExtensionNameFromUrl(String url){
230 | if ((url != null) && (url.length() > 0)) {
231 | int dot = url.lastIndexOf('.');
232 | if ((dot > -1) && (dot < (url.length() - 1))) {
233 | return url.substring(dot + 1);
234 | }
235 | }
236 | return "";
237 | }
238 |
239 | /**
240 | * 转换文件大小
241 | * @param fileS
242 | * @return
243 | */
244 | public static String FormetFileSize(long fileS)
245 | {
246 | DecimalFormat df = new DecimalFormat("#.00");
247 | String fileSizeString = "";
248 | String wrongSize="0B";
249 | if(fileS==0){
250 | return wrongSize;
251 | }
252 | if (fileS < 1024){
253 | fileSizeString = df.format((double) fileS) + "B";
254 | }
255 | else if (fileS < 1048576){
256 | fileSizeString = df.format((double) fileS / 1024) + "KB";
257 | }
258 | else if (fileS < 1073741824){
259 | fileSizeString = df.format((double) fileS / 1048576) + "MB";
260 | }
261 | else{
262 | fileSizeString = df.format((double) fileS / 1073741824) + "GB";
263 | }
264 | return fileSizeString;
265 | }
266 |
267 | /**
268 | * 返回文件名
269 | * @param uri
270 | * @return
271 | */
272 | public static String getFilename(Uri uri) {
273 | File file = new File(uri.getPath());
274 | if(!file.exists()) {
275 | return "";
276 | }
277 | return file.getName();
278 | }
279 |
280 | /**
281 | * Java文件操作 获取文件扩展名
282 | * Get the file extension, if no extension or file name
283 | *
284 | */
285 | public static String getExtensionName(Uri uri) {
286 | String filename=uri.getPath();
287 | if ((filename != null) && (filename.length() > 0)) {
288 | int dot = filename.lastIndexOf('.');
289 | if ((dot > -1) && (dot < (filename.length() - 1))) {
290 | return filename.substring(dot + 1);
291 | }
292 | }
293 | return "";
294 | }
295 |
296 | /**
297 | * 返回图片存放目录
298 | * @return
299 | */
300 | public static File getImagePathName() {
301 | if (!isExistExternalStore()) {
302 |
303 |
304 |
305 | return null;
306 | }
307 |
308 | File directory = new File(IMESSAGE_IMAGE);
309 | if (!directory.exists() && !directory.mkdirs()) {
310 |
311 | return null;
312 | }
313 |
314 | return directory;
315 | }
316 |
317 |
318 | /**
319 | * 返回文件存放目录
320 | * @return
321 | */
322 | public static File getFilePathName() {
323 | if (!isExistExternalStore()) {
324 |
325 | return null;
326 | }
327 |
328 | File directory = new File(IMESSAGE_FILE);
329 | if (!directory.exists() && !directory.mkdirs()) {
330 |
331 | return null;
332 | }
333 |
334 | return directory;
335 | }
336 | /**
337 | * 返回拍摄视频存放目录
338 | * @return
339 | */
340 | public static File getMovesPathName() {
341 | if (!isExistExternalStore()) {
342 |
343 | return null;
344 | }
345 |
346 | File directory = new File(IMESSAGE_MOVES);
347 | if (!directory.exists() && !directory.mkdirs()) {
348 |
349 | return null;
350 | }
351 |
352 | return directory;
353 | }
354 | /**
355 | * byte(字节)根据长度转成kb(千字节)和mb(兆字节)
356 | *
357 | * @param bytes
358 | * @return
359 | */
360 | public static String bytes2kb(long bytes) {
361 | BigDecimal filesize = new BigDecimal(bytes);
362 | BigDecimal megabyte = new BigDecimal(1024 * 1024);
363 | float returnValue = filesize.divide(megabyte, 2, BigDecimal.ROUND_UP)
364 | .floatValue();
365 | if (returnValue > 1)
366 | return (returnValue + "MB");
367 | BigDecimal kilobyte = new BigDecimal(1024);
368 | returnValue = filesize.divide(kilobyte, 2, BigDecimal.ROUND_UP)
369 | .floatValue();
370 | return (returnValue + "KB");
371 | }
372 | }
373 |
--------------------------------------------------------------------------------
/fileselector/src/main/java/choose/lm/com/fileselector/widget/CustomTitleBar.java:
--------------------------------------------------------------------------------
1 | package choose.lm.com.fileselector.widget;
2 |
3 | import android.content.Context;
4 | import android.databinding.DataBindingUtil;
5 | import android.graphics.Color;
6 | import android.support.annotation.StringRes;
7 | import android.util.AttributeSet;
8 | import android.util.TypedValue;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.LinearLayout;
14 | import android.widget.TextView;
15 |
16 | import java.util.HashMap;
17 |
18 | import choose.lm.com.fileselector.R;
19 | import choose.lm.com.fileselector.databinding.LibBaseTitlebarLayoutBinding;
20 |
21 |
22 | /**
23 | * Created by wjq on 2016/7/26.
24 | */
25 | public class CustomTitleBar extends LinearLayout implements View.OnClickListener {
26 |
27 | /**
28 | * 标题栏右侧区域的按钮集合
29 | */
30 | private HashMap _btns = new HashMap();
31 | private LibBaseTitlebarLayoutBinding mBinding;
32 |
33 | private Button _btn = null;
34 |
35 | /**
36 | * 标题栏左侧返回区域点击事件
37 | */
38 | private IBackClickListener _backClickListener = null;
39 |
40 | public CustomTitleBar(Context context) {
41 | this(context, null);
42 | }
43 |
44 | public CustomTitleBar(Context context, AttributeSet attrs) {
45 | super(context, attrs);
46 |
47 | mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.lib_base_titlebar_layout, this, true);
48 |
49 |
50 | if (isInEditMode()) {
51 | return;
52 | }
53 |
54 | mBinding.tvTitle.setOnClickListener(new OnClickListener() {
55 |
56 | @Override
57 | public void onClick(View v) {
58 |
59 | }
60 | });
61 |
62 |
63 | mBinding.lyBack.setOnClickListener(this);
64 | mBinding.ivBack.setOnClickListener(this);
65 | //this.setBackButtonVisiblity(AppManager.create().getCount()>1);
66 | }
67 |
68 | /**
69 | * 设置标题栏左侧返回按钮点击事件
70 | *
71 | * @param listener
72 | */
73 | public void setOnBackClickListener(IBackClickListener listener) {
74 | this._backClickListener = listener;
75 | }
76 |
77 | /**
78 | * 获取标题
79 | *
80 | * @return
81 | */
82 | public String getTitle() {
83 | return mBinding.tvTitle.getText().toString();
84 | }
85 |
86 | /**
87 | * 设置标题
88 | *
89 | * @param title
90 | */
91 | public void setTitle(String title) {
92 | mBinding.tvTitle.setText(title);
93 | }
94 |
95 | /**
96 | * 设置标题
97 | *
98 | * @param resId
99 | */
100 | public void setTitle(@StringRes int resId) {
101 | mBinding.tvTitle.setText(resId);
102 | }
103 |
104 | /**
105 | * 在标题栏右侧区域添加一个按钮(TextView类型的对象按钮)
106 | *
107 | * @param name 按钮的唯一名称(如果添加的按钮名称已经存在,则会抛出异常)
108 | * @param text 按钮显示的文本
109 | * @param listener 按钮的点击事件响应动作对象(null表示不做任何响应)
110 | * @throws Exception 相同名称的按钮已经存在
111 | */
112 | public void addRightAreaButton(String name, String text,
113 | OnClickListener listener) throws Exception {
114 | if (this._btns.containsKey(name)) {
115 | throw new Exception("该名称的按钮已经存在");
116 | } else {
117 | TextView txtV = new TextView(this.getContext());
118 | txtV.setText(text);
119 | txtV.setTextColor(Color.WHITE);
120 |
121 | txtV.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
122 | txtV.setClickable(true);
123 | txtV.setOnClickListener(listener);
124 | txtV.setGravity(Gravity.CENTER);
125 | LayoutParams pa = new LayoutParams(
126 | LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
127 | txtV.setPadding(20, 10, 20, 10);
128 | pa.gravity = Gravity.CENTER;
129 | if (this._btns.size() != 0) {
130 | pa.rightMargin = 20;
131 | }
132 | mBinding.lyRight.addView(txtV, 0, pa);
133 | this._btns.put(name, txtV);
134 | }
135 | }
136 |
137 | /**
138 | * 获取标题栏右侧区域的按钮对象
139 | *
140 | * @param name 按钮的唯一名称
141 | * @return
142 | */
143 | public TextView getRightAreaButton(String name) {
144 | return this._btns.get(name);
145 | }
146 |
147 | /**
148 | * 设置指定名称的按钮是否可用
149 | *
150 | * @param name 按钮名称
151 | * @param bool 是否可用
152 | */
153 | public void setButtonEnable(String name, Boolean bool) {
154 | if (this._btns.containsKey(name)) {
155 | this._btns.get(name).setEnabled(bool);
156 | }
157 | }
158 |
159 | /**
160 | * 设置指定名称的按钮的可见方式
161 | *
162 | * @param name 按钮名称
163 | * @param visiblity View.GONE(占位不可见)/View.INVISIBLE(不可见且不占位)/View.VISIBLE(可见)
164 | */
165 | public void setButtonVisible(String name, int visiblity) {
166 | if (this._btns.containsKey(name)) {
167 | this._btns.get(name).setVisibility(visiblity);
168 | }
169 | }
170 |
171 | /**
172 | * 设置指定名称的按钮事件响应对象
173 | *
174 | * @param name 按钮名称
175 | * @param listener 点击事件响应对象
176 | */
177 | public void setButtonClickListener(String name,
178 | OnClickListener listener) {
179 | if (this._btns.containsKey(name)) {
180 | this._btns.get(name).setOnClickListener(listener);
181 | }
182 | }
183 |
184 | @Override
185 | public void onClick(View v) {
186 | if (v.getId() == R.id.ly_back || v.getId() == R.id.iv_back) {
187 | if (this._backClickListener == null) {
188 | //AppManager.create().topActivity().finish();
189 | } else {
190 | this._backClickListener.OnBackClick();
191 | }
192 | }
193 | }
194 |
195 | /**
196 | * 设置标题栏返回按钮的显示或隐藏
197 | *
198 | * @param bool 显示:true 隐藏:false
199 | */
200 | public void setBackButtonVisiblity(boolean bool) {
201 | if (bool) {
202 | mBinding.lyBack.setVisibility(View.VISIBLE);
203 | mBinding.lyBack.setVisibility(View.VISIBLE);
204 | } else {
205 | mBinding.lyBack.setVisibility(View.INVISIBLE);
206 | mBinding.lyBack.setVisibility(View.INVISIBLE);
207 | }
208 | }
209 |
210 | public interface IBackClickListener {
211 | public void OnBackClick();
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_excel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_excel.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_mp3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_mp3.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_other.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_other.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_pdf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_pdf.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_pic.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_ppt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_ppt.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_rar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_rar.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_sort_arrow_up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_sort_arrow_up.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_staff_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_staff_checked.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_staff_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_staff_unchecked.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_txt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_txt.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_video.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_wj_jt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_wj_jt.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_wj_jt_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_wj_jt_on.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/ico_word.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/ico_word.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/im_icon_camera.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/im_icon_camera.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/im_icon_images.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/im_icon_images.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable-xhdpi/img_preloading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable-xhdpi/img_preloading.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable/choose_file_up_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable/lib_choose_file_send.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable/lib_sl_single_choice.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/drawable/nav_ico_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ax3726/ChooseFile/4bcdfd0f945a4a8b55b4bc2083f2b823047d5d19/fileselector/src/main/res/drawable/nav_ico_left.png
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_activity_choose_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
19 |
20 |
21 |
31 |
32 |
33 |
37 |
38 |
43 |
44 |
48 |
49 |
52 |
53 |
62 |
63 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_base_titlebar_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
20 |
21 |
33 |
34 |
35 |
36 |
47 |
48 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_item_file_group.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
20 |
21 |
28 |
29 |
37 |
38 |
39 |
40 |
41 |
45 |
51 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_item_image_group.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
21 |
22 |
29 |
30 |
38 |
39 |
40 |
41 |
42 |
46 |
52 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_item_photo_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_item_video_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
23 |
24 |
32 |
39 |
49 |
59 |
69 |
70 |
71 |
72 |
77 |
78 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_photo_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/layout/lib_video_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffffff
4 | #ebebeb
5 | #8a8a8a
6 | #15aaff
7 | #c9c9c9
8 | #dddddd
9 | #000000
10 | #777777
11 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FileSelector
3 |
4 |
--------------------------------------------------------------------------------
/fileselector/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':fileselector'
2 |
--------------------------------------------------------------------------------