├── .gitattributes
├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── will
│ │ └── example
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── will
│ │ │ └── example
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── will
│ └── example
│ └── ExampleUnitTest.java
├── build.gradle
├── filesearcher
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── will
│ │ └── filesearcher
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── will
│ │ │ └── filesearcher
│ │ │ ├── FileSearcher.java
│ │ │ ├── FileSearcherActivity.java
│ │ │ ├── FileSearcherAdapter.java
│ │ │ ├── delegate
│ │ │ └── FileSearcherDelegateActivity.java
│ │ │ ├── filter
│ │ │ └── FileFilter.java
│ │ │ ├── searchengine
│ │ │ ├── CallbackExecutor.java
│ │ │ ├── FileItem.java
│ │ │ └── SearchEngine.java
│ │ │ └── util
│ │ │ ├── FileSearcherUtil.java
│ │ │ └── IntervalTimer.java
│ └── res
│ │ ├── drawable-hdpi
│ │ ├── back_holo_dark_no_trim_no_padding.png
│ │ ├── check_holo_dark_no_padding_no_trim.png
│ │ ├── check_holo_dark_no_padding_trimmed.png
│ │ └── select_all_holo_dark_no_padding_no_trim.png
│ │ ├── drawable-mdpi
│ │ ├── back_holo_dark_no_trim_no_padding.png
│ │ ├── check_holo_dark_no_padding_no_trim.png
│ │ ├── check_holo_dark_no_padding_trimmed.png
│ │ └── select_all_holo_dark_no_padding_no_trim.png
│ │ ├── drawable-xhdpi
│ │ ├── back_holo_dark_no_trim_no_padding.png
│ │ ├── check_holo_dark_no_padding_no_trim.png
│ │ ├── check_holo_dark_no_padding_trimmed.png
│ │ ├── file_searcher_file_icon.png
│ │ └── select_all_holo_dark_no_padding_no_trim.png
│ │ ├── drawable-xxhdpi
│ │ ├── back_holo_dark_no_trim_no_padding.png
│ │ ├── check_holo_dark_no_padding_no_trim.png
│ │ ├── check_holo_dark_no_padding_trimmed.png
│ │ └── select_all_holo_dark_no_padding_no_trim.png
│ │ ├── layout
│ │ ├── file_searcher_item.xml
│ │ └── file_searcher_main.xml
│ │ ├── menu
│ │ └── file_searcher_activity_menu.xml
│ │ ├── values-zh
│ │ └── strings.xml
│ │ └── values
│ │ ├── color.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── will
│ └── filesearcher
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FileSearcher
2 | A simple fileSearcher.
3 |
4 | 
5 |
6 | ## How to
7 | start FileSearcherActivity from our activity,do not forget the keyword.
8 | ```java
9 | Intent intent = new Intent(MainActivity.this, FileSearcherActivity.class);
10 | intent.putExtra("keyword",".txt");
11 | //optional------
12 |
13 | //intent.putExtra("max",50 * 1024);//size filter
14 | intent.putExtra("min",50 * 1024);
15 | intent.putExtra("theme",R.style.SearchTheme);//set custom theme here
16 |
17 |
18 | startActivityForResult(intent,REQUEST_CODE);
19 | ```
20 | then we deal selected data in onActivityResult
21 | ```java
22 | @Override
23 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
24 | if(requestCode == REQUEST_CODE && resultCode ==FileSearcherActivity.OK && data != null){
25 | ArrayList list = ( ArrayList) data.getSerializableExtra("data");
26 | Toast.makeText(this,"you selected"+list.size()+"items",Toast.LENGTH_SHORT).show();
27 | }
28 | }
29 | ```
30 | ## Theme
31 | optional,you can use custom theme.
32 | ```xml
33 |
34 |
39 | ```
40 | ## Dependency
41 |
42 | Step 1. Add the JitPack repository to your build file
43 |
44 | Add it in your root build.gradle at the end of repositories:
45 |
46 | allprojects {
47 | repositories {
48 | ...
49 | maven { url "https://jitpack.io" }
50 | }
51 | }
52 | Step 2. Add the dependency
53 |
54 | dependencies {
55 | compile 'com.github.YuanWenHai:FileSearcher:1.3.3'
56 | }
57 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 | defaultConfig {
7 | applicationId "com.will.filesearcher"
8 | minSdkVersion 19
9 | targetSdkVersion 26
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 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | /*
28 | compile 'com.android.support:appcompat-v7:26.1.0'
29 | */
30 | testCompile 'junit:junit:4.12'
31 | compile project(':filesearcher')
32 | }
33 |
--------------------------------------------------------------------------------
/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 C:\Users\will\AppData\Local\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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/will/example/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.will.example;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.will.filesearcher", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/will/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.will.example;
2 |
3 | import android.app.ProgressDialog;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.CheckBox;
9 | import android.widget.EditText;
10 | import android.widget.Toast;
11 |
12 | import com.will.filesearcher.FileSearcher;
13 |
14 | import java.io.File;
15 | import java.io.IOException;
16 | import java.util.List;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 | private static final int REQUEST_CODE = 888;
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | //makeMockedData();
25 | final EditText keywordEdit = findViewById(R.id.example_keyword);
26 | final EditText extensionEdit = findViewById(R.id.example_extension);
27 | final EditText minSizeEdit = findViewById(R.id.example_min);
28 | final EditText maxSizeEdit = findViewById(R.id.example_max);
29 | final CheckBox showHiddenCheckBox = findViewById(R.id.example_show_hidden);
30 | Button button = (Button) findViewById(R.id.example_confirm);
31 | button.setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | String content = keywordEdit.getText().toString().replaceAll(" ","");
35 | String extension = extensionEdit.getText().toString();
36 | long minSize = Long.valueOf(minSizeEdit.getText().toString().isEmpty() ? "0" : minSizeEdit.getText().toString());
37 | long maxSize = Long.valueOf(maxSizeEdit.getText().toString().isEmpty() ? "-1" : maxSizeEdit.getText().toString());
38 | boolean showHidden = showHiddenCheckBox.isChecked();
39 |
40 | FileSearcher fileSearcher = new FileSearcher(MainActivity.this);
41 | fileSearcher
42 | .withKeyword(content)
43 | .withExtension(extension)
44 | .withSizeLimit(minSize,maxSize)
45 | .showHidden(showHidden)
46 | .search(new FileSearcher.FileSearcherCallback() {
47 | @Override
48 | public void onSelect(List files) {
49 | Toast.makeText(MainActivity.this, "you have selected "+files.size()+" file(s).", Toast.LENGTH_SHORT).show();
50 | }
51 | });
52 | }
53 | });
54 | }
55 | private void makeMockedData(){
56 |
57 | final File cacheDir = getExternalCacheDir();
58 | if(cacheDir != null){
59 | if(!cacheDir.exists()){
60 | cacheDir.mkdirs();
61 | }
62 | if(cacheDir.listFiles().length > 0){
63 | return;
64 | }
65 | final ProgressDialog p = new ProgressDialog(this);
66 | p.show();
67 | new Thread(new Runnable() {
68 | @Override
69 | public void run() {
70 | try{
71 | for(int i=0;i<200;i++){
72 | File dir = new File(cacheDir.getPath()+File.separator+i);
73 | dir.mkdir();
74 | for(int a=0;a<200;a++){
75 | File file = new File(dir.getPath()+File.separator+i+"-"+a);
76 | file.createNewFile();
77 | }
78 | }
79 |
80 | }catch (IOException i){
81 | i.printStackTrace();
82 | }finally {
83 | runOnUiThread(new Runnable() {
84 | @Override
85 | public void run() {
86 | p.cancel();
87 | }
88 | });
89 | }
90 | }
91 | }).start();
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
22 |
23 |
28 |
34 |
35 |
39 |
40 |
48 |
49 |
57 |
58 |
63 |
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #3F51B5
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FileSearcher
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/will/example/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.will.example;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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 | maven {
7 | url 'https://maven.google.com/'
8 | name 'Google'
9 | }
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:3.0.1'
13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | jcenter()
23 | maven {
24 | url 'https://maven.google.com/'
25 | name 'Google'
26 | }
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/filesearcher/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/filesearcher/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.YuanWenHai'
4 | android {
5 | compileSdkVersion 26
6 | buildToolsVersion "26.0.2"
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
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:26.1.0'
31 | testCompile 'junit:junit:4.12'
32 | compile 'com.android.support:recyclerview-v7:26.1.0'
33 | compile 'com.android.support:design:26.1.0'
34 | }
35 |
--------------------------------------------------------------------------------
/filesearcher/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 C:\Users\will\AppData\Local\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 |
--------------------------------------------------------------------------------
/filesearcher/src/androidTest/java/com/will/filesearcher/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.will.filesearcher.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/filesearcher/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
8 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/FileSearcher.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Environment;
6 | import android.support.annotation.NonNull;
7 |
8 | import com.will.filesearcher.delegate.FileSearcherDelegateActivity;
9 | import com.will.filesearcher.filter.FileFilter;
10 |
11 | import java.io.File;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by Will on 2017/10/31.
16 | */
17 |
18 | public class FileSearcher {
19 | private File path;
20 | static final String FILE_FILTER = "file_filter";
21 | static final String SEARCH_PATH = "search_path";
22 | private final FileFilter fileFilter = new FileFilter();
23 | private final Context context;
24 | public static FileSearcherCallback callback;
25 |
26 | /**
27 | *
28 | * @param context context
29 | */
30 | public FileSearcher(@NonNull Context context){
31 | this.context = context;
32 | }
33 |
34 | /**
35 | * search with detail limit
36 | * @param min minimum size in byte
37 | * @param max max size in byte,negative value is no limit
38 | * @return itself
39 | */
40 | public FileSearcher withSizeLimit(long min, long max){
41 | fileFilter.withSizeLimit(min,max);
42 | return this;
43 | }
44 |
45 | /**
46 | * search with extension
47 | * @param extension extension,such as txt,jpg.
48 | * @return itself
49 | */
50 | public FileSearcher withExtension(@NonNull String extension){
51 | fileFilter.withExtension(extension);
52 | return this;
53 | }
54 |
55 | /**
56 | * search with keyword
57 | * @param keyword keyword
58 | * @return itself
59 | */
60 | public FileSearcher withKeyword(@NonNull String keyword){
61 | fileFilter.withKeyword(keyword);
62 | return this;
63 | }
64 |
65 | /**
66 | * whether show hidden files or not(whether show files that prefix with '.'),default is not.
67 | * @param showHidden show or not
68 | * @return itself
69 | */
70 | public FileSearcher showHidden(boolean showHidden){
71 | fileFilter.showHidden(showHidden);
72 | return this;
73 | }
74 | public FileSearcher withRootPath(File path){
75 | this.path = path;
76 | return this;
77 | }
78 |
79 | /**
80 | * search with specified conditions,if passed path is invalid,an IllegalStatementException will be thrown.
81 | * @param callback
82 | */
83 | public void search(FileSearcherCallback callback){
84 | if(path == null){
85 | path = Environment.getExternalStorageDirectory();
86 | }else if(!path.isDirectory()){
87 | throw new IllegalArgumentException("the path must be a directory");
88 | }
89 | this.callback = callback;
90 | Intent intent = new Intent(context,FileSearcherDelegateActivity.class);
91 | intent.putExtra(FILE_FILTER,fileFilter);
92 | intent.putExtra(SEARCH_PATH,path);
93 | context.startActivity(intent);
94 | }
95 | public interface FileSearcherCallback{
96 | void onSelect(List files);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/FileSearcherActivity.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Bundle;
5 | import android.os.Environment;
6 | import android.support.annotation.Nullable;
7 | import android.support.design.widget.FloatingActionButton;
8 | import android.support.v7.app.AlertDialog;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.DividerItemDecoration;
11 | import android.support.v7.widget.LinearLayoutManager;
12 | import android.support.v7.widget.RecyclerView;
13 | import android.support.v7.widget.Toolbar;
14 | import android.view.Menu;
15 | import android.view.MenuItem;
16 | import android.view.View;
17 |
18 | import com.will.filesearcher.filter.FileFilter;
19 | import com.will.filesearcher.searchengine.FileItem;
20 | import com.will.filesearcher.searchengine.SearchEngine;
21 |
22 | import java.io.File;
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | /**
27 | * Created by Will on 2017/10/31.
28 | */
29 |
30 | public class FileSearcherActivity extends AppCompatActivity{
31 | private SearchEngine searchEngine;
32 | private FileSearcherAdapter adapter;
33 | private Toolbar toolbar;
34 | private List selectedItems;
35 | private View emptyView;
36 | @Override
37 | public void onCreate(@Nullable Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.file_searcher_main);
40 | initializeSearchEngine();
41 | initializeView();
42 | searchEngine.start();
43 | }
44 |
45 |
46 | private void initializeView(){
47 | emptyView = findViewById(R.id.file_searcher_main_no_result_found);
48 | toolbar = findViewById(R.id.file_searcher_main_toolbar);
49 | toolbar.setNavigationIcon(R.drawable.back_holo_dark_no_trim_no_padding);
50 | setSupportActionBar(toolbar);
51 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View view) {
54 | onBackPressed();
55 | }
56 | });
57 | FloatingActionButton fab = findViewById(R.id.file_searcher_main_fab);
58 | fab.setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View v) {
61 | if(searchEngine.isSearching()){
62 | return;
63 | }
64 | ArrayList list = new ArrayList<>();
65 | if(selectedItems != null){
66 | for(FileItem item : selectedItems){
67 | list.add(item.getFile());
68 | }
69 | }
70 | FileSearcher.callback.onSelect(list);
71 | finish();
72 | }
73 | });
74 | RecyclerView recyclerView = findViewById(R.id.file_searcher_main_recycler_view);
75 | adapter = new FileSearcherAdapter(this,searchEngine);
76 | adapter.setOnItemSelectCallback(new FileSearcherAdapter.OnItemSelectCallback() {
77 |
78 | @Override
79 | public void onSelectStateChanged(List items) {
80 | if(selectedItems == null){
81 | selectedItems = items;
82 | }
83 | toolbar.setTitle(selectedItems.size()+"/"+adapter.getItemCount());
84 | }
85 |
86 |
87 | });
88 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
89 | recyclerView.setAdapter(adapter);
90 | recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
91 | }
92 | private void initializeSearchEngine(){
93 | FileFilter filter = (FileFilter) getIntent().getSerializableExtra(FileSearcher.FILE_FILTER);
94 | File path = (File) getIntent().getSerializableExtra(FileSearcher.SEARCH_PATH);
95 | if(filter == null || path == null){
96 | throw new NullPointerException("the filter and path cannot be null!");
97 | }
98 | searchEngine = new SearchEngine(path,filter);
99 | searchEngine.setCallback(new SearchEngine.SearchEngineCallback() {
100 | @Override
101 | public void onFind(List items) {
102 | adapter.addItem(items);
103 | }
104 |
105 | @Override
106 | public void onSearchDirectory(File file) {
107 | toolbar.setSubtitle( file.getPath().replace(Environment.getExternalStorageDirectory().getPath()+File.separator,""));
108 | }
109 |
110 | @Override
111 | public void onFinish() {
112 | if(adapter.getItemCount() == 0){
113 | emptyView.setVisibility(View.VISIBLE);
114 | }
115 | toolbar.setTitle("0/"+adapter.getItemCount());
116 | toolbar.setSubtitle(getString(com.will.filesearcher.R.string.file_searcher_searching_completed));
117 | }
118 | });
119 | }
120 |
121 | @Override
122 | public void onBackPressed() {
123 | if(searchEngine.isSearching()){
124 | showCancelDialog();
125 | }else{
126 | super.onBackPressed();
127 | }
128 | }
129 | private void showCancelDialog(){
130 | new AlertDialog.Builder(this)
131 | .setTitle(getString(R.string.file_searcher_cancel_search)).
132 | setPositiveButton(getString(R.string.file_searcher_confirm), new DialogInterface.OnClickListener() {
133 | @Override
134 | public void onClick(DialogInterface dialog, int which) {
135 | searchEngine.stop();
136 | }
137 | }).setNegativeButton(getString(R.string.file_searcher_cancel),null)
138 | .create().show();
139 | }
140 |
141 | @Override
142 | public boolean onCreateOptionsMenu(Menu menu) {
143 | getMenuInflater().inflate(com.will.filesearcher.R.menu.file_searcher_activity_menu,menu);
144 | return true;
145 | }
146 |
147 | @Override
148 | protected void onDestroy() {
149 | super.onDestroy();
150 | FileSearcher.callback = null;
151 | }
152 |
153 | @Override
154 | public boolean onOptionsItemSelected(MenuItem item) {
155 | if(item.getItemId() == com.will.filesearcher.R.id.file_searcher_menu_select_all && !searchEngine.isSearching()){
156 |
157 | adapter.selectAll();
158 | return true;
159 | }
160 | return super.onOptionsItemSelected(item);
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/FileSearcherAdapter.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.CheckBox;
11 | import android.widget.CompoundButton;
12 | import android.widget.TextView;
13 |
14 | import com.will.filesearcher.searchengine.FileItem;
15 | import com.will.filesearcher.searchengine.SearchEngine;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | /**
21 | * Created by Will on 2017/11/1.
22 | */
23 |
24 | public class FileSearcherAdapter extends RecyclerView.Adapter {
25 | private List items = new ArrayList<>();
26 | private List selectedItems = new ArrayList<>();
27 | private OnItemSelectCallback callback;
28 | private final int colorUnchecked;
29 | private final int colorChecked;
30 | private SearchEngine searchEngine;
31 |
32 | public FileSearcherAdapter(Context context,@NonNull SearchEngine searchEngine){
33 | colorUnchecked = context.getResources().getColor(R.color.fileSearcherWhite);
34 | colorChecked = context.getResources().getColor(R.color.fileSearcherCheckedBackground);
35 | this.searchEngine = searchEngine;
36 | }
37 |
38 | @Override
39 | public FileSearcherVH onCreateViewHolder(ViewGroup parent, int viewType) {
40 | return new FileSearcherVH(LayoutInflater.from(parent.getContext()).inflate(R.layout.file_searcher_item,parent,false));
41 | }
42 |
43 | @Override
44 | public void onBindViewHolder(FileSearcherVH holder, int position) {
45 | FileItem item = items.get(position);
46 | holder.title.setText(item.getName());
47 | holder.path.setText(item.getPath());
48 | holder.detail.setText(item.getDetail());
49 | holder.checkBox.setChecked(item.isChecked());
50 | holder.itemView.setBackgroundColor(item.isChecked()? colorChecked : colorUnchecked);
51 | }
52 |
53 | @Override
54 | public int getItemCount() {
55 | return items.size();
56 | }
57 |
58 | public void addItem(FileItem item){
59 | items.add(item);
60 | notifyDataSetChanged();
61 | }
62 | public void addItem(List item){
63 | items.addAll(item);
64 | notifyDataSetChanged();
65 | }
66 |
67 | public void selectAll(){
68 | boolean isAllSelected = isAllSelected();
69 | for(FileItem item : items){
70 | item.setChecked(!isAllSelected);
71 | }
72 | notifyDataSetChanged();
73 | if(!isAllSelected){
74 | selectedItems.clear();
75 | selectedItems.addAll(items);
76 | }else{
77 | selectedItems.clear();
78 | }
79 | if(callback != null){
80 | callback.onSelectStateChanged(selectedItems);
81 | }
82 | }
83 | private boolean isAllSelected(){
84 | for (FileItem item : items){
85 | if (!item.isChecked()){
86 | return false;
87 | }
88 | }
89 | return true;
90 | }
91 | public void setOnItemSelectCallback(OnItemSelectCallback callback){
92 | this.callback = callback;
93 | }
94 |
95 | class FileSearcherVH extends RecyclerView.ViewHolder{
96 | TextView title, detail, path;
97 | CheckBox checkBox;
98 | public FileSearcherVH(final View itemView) {
99 | super(itemView);
100 | title = itemView.findViewById(R.id.file_searcher_item_text_title);
101 | detail = itemView.findViewById(R.id.file_searcher_item_text_detail);
102 | path = itemView.findViewById(R.id.file_searcher_item_text_path);
103 | checkBox = itemView.findViewById(R.id.file_searcher_item_check_box);
104 | itemView.setOnClickListener(new View.OnClickListener() {
105 | @Override
106 | public void onClick(View view) {
107 | checkBox.performClick();
108 | //items.get(getLayoutPosition()).setChecked(checkBox.isChecked());
109 | }
110 | });
111 | checkBox.setOnClickListener(new View.OnClickListener() {
112 | @Override
113 | public void onClick(View view) {
114 | if(searchEngine.isSearching()){
115 | return;
116 | }
117 | boolean b = checkBox.isChecked();
118 | items.get(getLayoutPosition()).setChecked(b);
119 | itemView.setBackgroundColor(b ? colorChecked : colorUnchecked );
120 | if(b){
121 | selectedItems.add(items.get(getLayoutPosition()));
122 | }else{
123 | selectedItems.remove(items.get(getLayoutPosition()));
124 | }
125 | if(callback != null){
126 | callback.onSelectStateChanged(selectedItems);
127 | }
128 | }
129 | });
130 | }
131 | }
132 | interface OnItemSelectCallback {
133 | void onSelectStateChanged(List items);
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/delegate/FileSearcherDelegateActivity.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher.delegate;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 | import android.support.v4.app.ActivityCompat;
10 | import android.support.v4.content.ContextCompat;
11 | import android.support.v7.app.AppCompatActivity;
12 |
13 | import com.will.filesearcher.FileSearcherActivity;
14 |
15 | /**
16 | * Created by Will on 2017/11/1.
17 | */
18 |
19 | public class FileSearcherDelegateActivity extends AppCompatActivity {
20 | @Override
21 | protected void onCreate(@Nullable Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | checkPermission();
24 | }
25 | private void checkPermission(){
26 | if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
27 | ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},888);
28 | }else{
29 | Intent intent = getIntent().setClass(this, FileSearcherActivity.class);
30 | startActivity(intent);
31 | finish();
32 | }
33 | }
34 |
35 | @Override
36 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
37 | if(requestCode == 888 && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
38 | Intent intent = getIntent().setClass(this, FileSearcherActivity.class);
39 | startActivity(intent);
40 | }
41 | finish();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/filter/FileFilter.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher.filter;
2 |
3 | import java.io.File;
4 | import java.io.Serializable;
5 |
6 | /**
7 | * Created by Will on 2017/11/1.
8 | */
9 |
10 | public class FileFilter implements Serializable{
11 | private long minimumSize = 0;
12 | private long maxSize = -1;
13 | private String extension = null;
14 | private String keyword = null;
15 | private boolean showHidden;
16 | public void withSizeLimit(long minimum, long max){
17 | minimumSize = minimum;
18 | maxSize = max;
19 | }
20 | public void withExtension(String extension){
21 | this.extension = extension;
22 | }
23 | public void withKeyword(String keyword){
24 | this.keyword = keyword;
25 | }
26 | public void showHidden(boolean showHidden){
27 | this.showHidden = showHidden;
28 | }
29 | public boolean filter(File file){
30 | //Log.d("fileFilter",file.getName());
31 | return sizeFilter(file) && extensionFilter(file) && keywordFilter(file) && hiddenFileFilter(file);
32 | }
33 | public boolean isShowHidden(){
34 | return showHidden;
35 | }
36 | private boolean sizeFilter(File file){
37 | boolean sizeResult;
38 | sizeResult = file.length() >= minimumSize;
39 | if(maxSize > -1){
40 | sizeResult = sizeResult && file.length() <= maxSize;
41 | }
42 | return sizeResult;
43 | }
44 | private boolean extensionFilter(File file){
45 | if(extension == null || extension.isEmpty()){
46 | return true;
47 | }
48 | String fileName = file.getName();
49 | return fileName.contains(".") && fileName.substring(fileName.lastIndexOf(".")+1,fileName.length()).toUpperCase().equals(extension.toUpperCase());
50 | }
51 | private boolean keywordFilter(File file){
52 | if(keyword == null || keyword.isEmpty() ){
53 | return true;
54 | }
55 | String fileName = file.getName();
56 | return fileName.toUpperCase().contains(keyword.toUpperCase());
57 | }
58 | private boolean hiddenFileFilter(File file){
59 | return showHidden || !file.getName().startsWith(".");
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/searchengine/CallbackExecutor.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher.searchengine;
2 |
3 | import android.os.Environment;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 |
7 | import java.io.File;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import com.will.filesearcher.searchengine.SearchEngine.SearchEngineCallback;
11 |
12 | /**
13 | * Created by will on 2017/12/2.
14 | */
15 | class CallbackExecutor {
16 | private final SearchEngineCallback callback;
17 | private final long interval;
18 |
19 | private volatile Handler handler;
20 |
21 | private List cachedItems = new ArrayList<>();
22 | private File currentDirectory = Environment.getExternalStorageDirectory();
23 | private volatile boolean isFinished;
24 |
25 | CallbackExecutor(SearchEngineCallback callback,long interval){
26 | this.callback = callback;
27 | this.interval = interval;
28 | }
29 |
30 | void onFind(FileItem item){
31 | if(handler == null){
32 | handler = new Handler(Looper.getMainLooper());
33 | handler.post(new Timer());
34 | }
35 | synchronized(callback){
36 | cachedItems.add(item);
37 | }
38 | }
39 |
40 |
41 | void onSearchDirectory(File file) {
42 | if(handler == null){
43 | handler = new Handler(Looper.getMainLooper());
44 | handler.post(new Timer());
45 | }
46 | currentDirectory = file;
47 | }
48 |
49 | void onFinish() {
50 | isFinished = true;
51 | }
52 | class Timer implements Runnable{
53 | @Override
54 | public void run() {
55 | synchronized(callback){
56 | callback.onFind(cachedItems);
57 | cachedItems.clear();
58 | callback.onSearchDirectory(currentDirectory);
59 | if(isFinished){
60 | callback.onFinish();
61 | return;
62 | }
63 | handler.postDelayed(this, interval);
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/searchengine/FileItem.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher.searchengine;
2 |
3 | import android.os.Environment;
4 |
5 | import com.will.filesearcher.util.FileSearcherUtil;
6 |
7 | import java.io.File;
8 | import java.text.SimpleDateFormat;
9 | import java.util.Date;
10 |
11 | /**
12 | * Created by Will on 2017/11/3.
13 | */
14 |
15 | public class FileItem{
16 | static String storagePath = Environment.getExternalStorageDirectory().getPath() + File.separator;
17 | static SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd,HH:mm");
18 |
19 |
20 |
21 | private String name,detail,path;
22 | private File file;
23 | private boolean isChecked;
24 |
25 | public FileItem(File file){
26 | this.file = file;
27 | this.name = file.getName();
28 | this.detail = FileSearcherUtil.byteSizeFormatter(file.length())+","+FileItem.formatter.format(new Date(file.lastModified()));
29 | this.path = file.getPath().replace(storagePath,"");
30 | isChecked = false;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public String getDetail() {
38 | return detail;
39 | }
40 |
41 | public String getPath() {
42 | return path;
43 | }
44 |
45 | public File getFile() {
46 | return file;
47 | }
48 |
49 | public boolean isChecked() {
50 | return isChecked;
51 | }
52 | public void setChecked(boolean isChecked){
53 | this.isChecked = isChecked;
54 | }
55 | }
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/searchengine/SearchEngine.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher.searchengine;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 | import android.os.SystemClock;
6 |
7 | import com.will.filesearcher.filter.FileFilter;
8 |
9 | import java.io.File;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by Will on 2017/11/1.
15 | */
16 |
17 | public class SearchEngine {
18 | private final File path;
19 | private final FileFilter filter;
20 | private boolean isSearching;
21 | private volatile boolean stop;
22 | private SearchEngineCallback callback;
23 | private CallbackExecutor callbackExecutor;
24 |
25 | public SearchEngine(File path, FileFilter filter){
26 | this.path = path;
27 | this.filter = filter;
28 | }
29 | public void start(final SearchEngineCallback callback){
30 | isSearching = true;
31 | stop = false;
32 | callbackExecutor = new CallbackExecutor(callback,200);
33 | new Thread(new Runnable() {
34 | @Override
35 | public void run() {
36 | findFileRecursively(path);
37 | callbackExecutor.onFinish();
38 | isSearching = false;
39 | }
40 | }).start();
41 | }
42 | public void start(){
43 | if(callback != null){
44 | start(callback);
45 | }
46 | }
47 | public void stop(){
48 | stop = isSearching;
49 | }
50 | public boolean isSearching(){
51 | return isSearching;
52 | }
53 |
54 | public void setCallback(SearchEngineCallback callback){
55 | this.callback = callback;
56 | }
57 | private void findFileRecursively(final File file){
58 | if(stop || !filter.isShowHidden() && file.getName().startsWith(".")){
59 | return;
60 | }
61 | //Log.d("file name",file.getName());
62 | if(file.isDirectory() ){
63 | File[] files = file.listFiles();
64 | if(files != null){
65 | callbackExecutor.onSearchDirectory(file);
66 | for(File f : files){
67 | findFileRecursively(f);
68 | }
69 | }
70 | }else{
71 | if(filter.filter(file)){
72 | FileItem item = new FileItem(file);
73 | callbackExecutor.onFind(item);
74 | }
75 | }
76 | }
77 |
78 | public interface SearchEngineCallback{
79 | void onFind(List fileItems);
80 | void onSearchDirectory(File file);
81 | void onFinish();
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/util/FileSearcherUtil.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher.util;
2 |
3 | import java.text.DecimalFormat;
4 |
5 | /**
6 | * Created by Will on 2017/11/1.
7 | */
8 |
9 | public class FileSearcherUtil {
10 |
11 | public static String byteSizeFormatter(long size){
12 | if(size == 0){
13 | return "0b";
14 | }
15 | String[] units = new String[]{"b","kb","mb","gb"};
16 | double power = Math.log10(1024);
17 | int level = (int)(Math.log10(size)/power);
18 | double factor = Math.pow(1024,level);
19 | return new DecimalFormat("#.##").format((double)size/factor) + units[level];
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/filesearcher/src/main/java/com/will/filesearcher/util/IntervalTimer.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher.util;
2 |
3 | /**
4 | * Created by will on 2017/11/19.
5 | */
6 |
7 | public class IntervalTimer {
8 | private final long interval;
9 |
10 | public IntervalTimer(long interval){
11 | this.interval = interval;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-hdpi/back_holo_dark_no_trim_no_padding.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-hdpi/back_holo_dark_no_trim_no_padding.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-hdpi/check_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-hdpi/check_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-hdpi/check_holo_dark_no_padding_trimmed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-hdpi/check_holo_dark_no_padding_trimmed.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-hdpi/select_all_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-hdpi/select_all_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-mdpi/back_holo_dark_no_trim_no_padding.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-mdpi/back_holo_dark_no_trim_no_padding.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-mdpi/check_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-mdpi/check_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-mdpi/check_holo_dark_no_padding_trimmed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-mdpi/check_holo_dark_no_padding_trimmed.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-mdpi/select_all_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-mdpi/select_all_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xhdpi/back_holo_dark_no_trim_no_padding.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xhdpi/back_holo_dark_no_trim_no_padding.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xhdpi/check_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xhdpi/check_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xhdpi/check_holo_dark_no_padding_trimmed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xhdpi/check_holo_dark_no_padding_trimmed.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xhdpi/file_searcher_file_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xhdpi/file_searcher_file_icon.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xhdpi/select_all_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xhdpi/select_all_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xxhdpi/back_holo_dark_no_trim_no_padding.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xxhdpi/back_holo_dark_no_trim_no_padding.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xxhdpi/check_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xxhdpi/check_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xxhdpi/check_holo_dark_no_padding_trimmed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xxhdpi/check_holo_dark_no_padding_trimmed.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/drawable-xxhdpi/select_all_holo_dark_no_padding_no_trim.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/filesearcher/src/main/res/drawable-xxhdpi/select_all_holo_dark_no_padding_no_trim.png
--------------------------------------------------------------------------------
/filesearcher/src/main/res/layout/file_searcher_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
13 |
20 |
26 |
30 |
34 |
35 |
42 |
43 |
--------------------------------------------------------------------------------
/filesearcher/src/main/res/layout/file_searcher_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
17 |
18 |
24 |
25 |
26 |
35 |
43 |
--------------------------------------------------------------------------------
/filesearcher/src/main/res/menu/file_searcher_activity_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/filesearcher/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 检索结果:
4 | 取消?
5 | 确定
6 | 放弃搜索?
7 | 未发现符合条件的文件.
8 | 修改时间:
9 | 文件名:
10 | 文件路径:
11 | 全选
12 | "正在搜索目录: "
13 | 取消
14 | 搜索完成
15 |
--------------------------------------------------------------------------------
/filesearcher/src/main/res/values/color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #3f51b5
6 | #00000000
7 | #333333
8 | #ffffff
9 | #E8EAF6
10 | #808080
11 |
12 |
--------------------------------------------------------------------------------
/filesearcher/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Search Result:
3 | Searching in :
4 | Confirm
5 | Cancel?
6 | Cancel
7 | Quit Searching?
8 | Select All
9 | done
10 | No result found.
11 | Name:
12 | Path:
13 | Size:
14 | Modified time:
15 | Searching completed.
16 |
17 |
--------------------------------------------------------------------------------
/filesearcher/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
18 |
28 |
31 |
35 |
36 |
--------------------------------------------------------------------------------
/filesearcher/src/test/java/com/will/filesearcher/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.will.filesearcher;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Sun Nov 05 23:04:38 CST 2017
16 | systemProp.http.proxyHost=127.0.0.1
17 | org.gradle.jvmargs=-Xmx4096m
18 | org.gradle.daemon=true
19 | org.gradle.parallel=true
20 | systemProp.http.proxyPort=1080
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuanWenHai/FileSearcher/5a3ae39b41a3ef8860a3477d34c19ec4857e7492/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Oct 29 13:56:50 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 | org.gradle.jvmargs=-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080
8 |
9 |
--------------------------------------------------------------------------------
/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', ':filesearcher'
2 |
--------------------------------------------------------------------------------