├── .gitignore ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── codekong │ │ └── fileexplorer │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── codekong │ │ │ └── fileexplorer │ │ │ ├── activity │ │ │ ├── BaseActivity.java │ │ │ └── MainActivity.java │ │ │ ├── adapter │ │ │ ├── CommonAdapter.java │ │ │ ├── FileListAdapter.java │ │ │ ├── SwitchViewPagerAdapter.java │ │ │ └── ViewHolder.java │ │ │ ├── bean │ │ │ └── Category.java │ │ │ ├── config │ │ │ └── Constant.java │ │ │ ├── fragment │ │ │ ├── BaseFragment.java │ │ │ ├── FileCategoryFragment.java │ │ │ └── FileListFragment.java │ │ │ ├── listener │ │ │ └── OnClickMenuListener.java │ │ │ ├── util │ │ │ ├── BackHandlerHelper.java │ │ │ ├── FileUtils.java │ │ │ ├── FragmentBackHandlerInterface.java │ │ │ ├── ScanFileCountUtil.java │ │ │ └── ViewUtils.java │ │ │ └── view │ │ │ ├── HideHeaderListView.java │ │ │ ├── OperationMenuPopupWindow.java │ │ │ └── SortMenuPopupWindow.java │ └── res │ │ ├── anim │ │ ├── top_in.xml │ │ └── top_out.xml │ │ ├── drawable-mdpi │ │ └── ic_action_name.png │ │ ├── drawable-xhdpi │ │ ├── ic_action_name.png │ │ ├── ic_apk.png │ │ ├── ic_bluetooth.png │ │ ├── ic_cloud_disk.png │ │ ├── ic_default.png │ │ ├── ic_document.png │ │ ├── ic_download.png │ │ ├── ic_favorites.png │ │ ├── ic_file.png │ │ ├── ic_folder.png │ │ ├── ic_music.png │ │ ├── ic_picture.png │ │ ├── ic_popular_expression.png │ │ ├── ic_remote_manage.png │ │ ├── ic_video.png │ │ └── ic_zip.png │ │ ├── drawable-xxhdpi │ │ └── ic_action_name.png │ │ ├── drawable │ │ ├── ic_add_black_24dp.xml │ │ ├── ic_arrow_drop_down_24dp.xml │ │ ├── ic_close_24dp.xml │ │ ├── ic_content_copy_24dp.xml │ │ ├── ic_content_paste_black_24dp.xml │ │ ├── ic_divider_line_gray.xml │ │ ├── ic_format_list_numbered_24dp.xml │ │ ├── ic_more_vert_black_24dp.xml │ │ ├── ic_next_24dp.xml │ │ ├── ic_search_24dp.xml │ │ └── radius_rect_shape.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── category_item.xml │ │ ├── common_app_item.xml │ │ ├── file_item.xml │ │ ├── fragment_file_category.xml │ │ ├── fragment_file_list.xml │ │ ├── input_layout.xml │ │ ├── item_header.xml │ │ ├── operation_popup_window_menu.xml │ │ └── sort_popup_window_menu.xml │ │ ├── menu │ │ └── file_list_menu.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 │ └── codekong │ └── fileexplorer │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── 1.png └── 2.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Example user template template 3 | ### Example user template 4 | 5 | # IntelliJ project files 6 | .idea 7 | *.iml 8 | out 9 | gen### Android template 10 | # Built application files 11 | *.apk 12 | *.ap_ 13 | 14 | # Files for the ART/Dalvik VM 15 | *.dex 16 | 17 | # Java class files 18 | *.class 19 | 20 | # Generated files 21 | bin/ 22 | gen/ 23 | out/ 24 | 25 | # Gradle files 26 | .gradle/ 27 | build/ 28 | 29 | # Local configuration file (sdk path, etc) 30 | local.properties 31 | 32 | # Proguard folder generated by Eclipse 33 | proguard/ 34 | 35 | # Log Files 36 | *.log 37 | 38 | # Android Studio Navigation editor temp files 39 | .navigation/ 40 | 41 | # Android Studio captures folder 42 | captures/ 43 | 44 | # Intellij 45 | .idea/workspace.xml 46 | .idea/tasks.xml 47 | .idea/libraries 48 | 49 | # Keystore files 50 | *.jks 51 | 52 | # External native build folder generated in Android Studio 2.2 and later 53 | .externalNativeBuild 54 | 55 | app/libs/ 56 | app/src/main/res/drawable-hdpi/ 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 仿小米文件管理器 2 | 3 | ### 实现功能 4 | 5 | 1. 文件分类统计列表展示 6 | 7 | 2. 文件目录展示 8 | 9 | 3. 下拉菜单操作 10 | 11 | 4. 文件排序 12 | 13 | 5. 下拉刷新数据 14 | 15 | ### 应用截图 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | android { 3 | compileSdkVersion 27 4 | buildToolsVersion "27.0.2" 5 | defaultConfig { 6 | applicationId "com.codekong.fileexplorer" 7 | minSdkVersion 16 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(include: ['*.jar'], dir: 'libs') 23 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 24 | exclude group: 'com.android.support', module: 'support-annotations' 25 | }) 26 | //compile 'com.android.support:appcompat-v7:26.1.0' 27 | testCompile 'junit:junit:4.12' 28 | implementation 'com.jakewharton:butterknife:8.5.1' 29 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 30 | implementation 'com.android.support:appcompat-v7:27.0.2' 31 | implementation 'com.android.support:design:27.0.2' 32 | implementation 'net.qiujuer.genius:ui:2.0.0' 33 | implementation 'net.qiujuer.genius:res:2.0.0' 34 | implementation 'com.jwenfeng.pulltorefresh:library:1.0.1' 35 | implementation 'pub.devrel:easypermissions:0.4.0' 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this ic_file are appended to flags specified 3 | # in G:\SDK\android-sdk-windows/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/codekong/fileexplorer/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer; 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 | /** 11 | * Instrumentation test, which will execute on an Android device. 12 | * 13 | * @see Testing documentation 14 | */ 15 | @RunWith(AndroidJUnit4.class) 16 | public class ExampleInstrumentedTest { 17 | @Test 18 | public void useAppContext() throws Exception { 19 | // Context of the app under test. 20 | Context appContext = InstrumentationRegistry.getTargetContext(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.activity; 2 | 3 | import android.os.Bundle; 4 | import android.os.PersistableBundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | /** 8 | * Created by szh on 2017/2/10. 9 | */ 10 | 11 | public class BaseActivity extends AppCompatActivity{ 12 | 13 | @Override 14 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { 15 | super.onCreate(savedInstanceState, persistentState); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.activity; 2 | 3 | import android.content.DialogInterface; 4 | import android.os.Bundle; 5 | import android.os.Environment; 6 | import android.support.design.widget.TabLayout; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.app.FragmentPagerAdapter; 9 | import android.support.v4.view.ViewPager; 10 | import android.support.v7.app.AlertDialog; 11 | import android.text.TextUtils; 12 | import android.view.Gravity; 13 | import android.view.View; 14 | import android.widget.EditText; 15 | import android.widget.ImageView; 16 | import android.widget.LinearLayout; 17 | import android.widget.PopupWindow; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import com.codekong.fileexplorer.R; 22 | import com.codekong.fileexplorer.adapter.SwitchViewPagerAdapter; 23 | import com.codekong.fileexplorer.fragment.FileListFragment; 24 | import com.codekong.fileexplorer.util.FileUtils; 25 | import com.codekong.fileexplorer.util.ViewUtils; 26 | import com.codekong.fileexplorer.view.OperationMenuPopupWindow; 27 | import com.codekong.fileexplorer.view.SortMenuPopupWindow; 28 | 29 | import java.io.File; 30 | 31 | import butterknife.BindView; 32 | import butterknife.ButterKnife; 33 | import butterknife.OnClick; 34 | import butterknife.Unbinder; 35 | 36 | public class MainActivity extends BaseActivity{ 37 | private static final String TAG = "MainActivity"; 38 | @BindView(R.id.id_more_operation) 39 | ImageView mMoreOperation; 40 | @BindView(R.id.id_switch_tab_layout) 41 | TabLayout mSwitchTabLayout; 42 | @BindView(R.id.id_switch_view_pager) 43 | ViewPager mSwitchViewPager; 44 | private Unbinder mUnbinder; 45 | 46 | private SwitchViewPagerAdapter mSwitchViewPagerAdapter; 47 | //上一次按返回键的时间 48 | private long mLastBackPressedTime = 0; 49 | //当前被选中的Fragment的position 50 | private int mCurrentFragmentPosition = 0; 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | super.onCreate(savedInstanceState); 55 | setContentView(R.layout.activity_main); 56 | mUnbinder = ButterKnife.bind(this); 57 | initView(); 58 | } 59 | 60 | private void initView() { 61 | //设置状态栏的白底黑字 62 | ViewUtils.MIUISetStatusBarLightMode(getWindow(), true); 63 | mSwitchViewPagerAdapter = new SwitchViewPagerAdapter(this, getSupportFragmentManager()); 64 | mSwitchViewPager.setAdapter(mSwitchViewPagerAdapter); 65 | mSwitchTabLayout.setupWithViewPager(mSwitchViewPager); 66 | 67 | mSwitchViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 68 | @Override 69 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 70 | 71 | } 72 | 73 | @Override 74 | public void onPageSelected(int position) { 75 | mCurrentFragmentPosition = position; 76 | if (position == 1) { 77 | mMoreOperation.setVisibility(View.VISIBLE); 78 | } else if (position == 0) { 79 | mMoreOperation.setVisibility(View.GONE); 80 | } 81 | } 82 | 83 | @Override 84 | public void onPageScrollStateChanged(int state) { 85 | 86 | } 87 | }); 88 | } 89 | 90 | @Override 91 | public void onBackPressed() { 92 | if (mCurrentFragmentPosition == 1) { 93 | //当前在手机文件管理页面的根目录 94 | if (FileUtils.getNowPath().equals(Environment.getExternalStorageDirectory().getAbsolutePath())) { 95 | //退出应用 96 | quitApplication(); 97 | } else { 98 | //返回上级目录 99 | FileListFragment.mNowPathStack.pop(); 100 | FragmentPagerAdapter fragmentPagerAdapter = (FragmentPagerAdapter) mSwitchViewPager.getAdapter(); 101 | FileListFragment fileListFragment = (FileListFragment) fragmentPagerAdapter.instantiateItem(mSwitchViewPager, 1); 102 | fileListFragment.showChange(FileUtils.getNowStackPathString(FileListFragment.mNowPathStack)); 103 | } 104 | } else { 105 | //退出应用 106 | quitApplication(); 107 | } 108 | } 109 | 110 | /** 111 | * 双击退出应用 112 | */ 113 | private void quitApplication() { 114 | if (System.currentTimeMillis() - mLastBackPressedTime > 2000) { 115 | Toast.makeText(this, R.string.str_again_click_exit, Toast.LENGTH_SHORT).show(); 116 | mLastBackPressedTime = System.currentTimeMillis(); 117 | } else { 118 | finish(); 119 | } 120 | } 121 | 122 | @Override 123 | protected void onDestroy() { 124 | super.onDestroy(); 125 | mUnbinder.unbind(); 126 | } 127 | 128 | @OnClick(R.id.id_more_operation) 129 | public void onClick() { 130 | final OperationMenuPopupWindow operationMenuPopupWindow = new OperationMenuPopupWindow(this.getSupportFragmentManager().getFragments().get(mCurrentFragmentPosition)); 131 | operationMenuPopupWindow.showAtLocation(findViewById(R.id.id_main_activity), Gravity.TOP, 0, 0); 132 | operationMenuPopupWindow.setOnWindowItemClickListener(new OperationMenuPopupWindow.OnWindowItemClickListener() { 133 | @Override 134 | public void closeMenu() { 135 | MainActivity.this.closeMenu(operationMenuPopupWindow); 136 | } 137 | 138 | @Override 139 | public void sort(String path) { 140 | MainActivity.this.closeMenu(operationMenuPopupWindow); 141 | showSortMethodMenu(); 142 | } 143 | 144 | @Override 145 | public void newFolder(final String path) { 146 | MainActivity.this.closeMenu(operationMenuPopupWindow); 147 | final View view = (LinearLayout) getLayoutInflater().inflate(R.layout.input_layout, null); 148 | //新文件名输入框 149 | final EditText et = view.findViewById(R.id.id_input_ed); 150 | //自定义弹出框标题 151 | final TextView titleTv = new TextView(MainActivity.this); 152 | titleTv.setText(MainActivity.this.getString(R.string.str_new_folder)); 153 | titleTv.setTextSize(16); 154 | titleTv.setGravity(Gravity.CENTER_HORIZONTAL); 155 | new AlertDialog.Builder(MainActivity.this) 156 | .setView(view) 157 | .setCancelable(false) 158 | .setPositiveButton(MainActivity.this.getString(R.string.str_new_create), new DialogInterface.OnClickListener() { 159 | @Override 160 | public void onClick(DialogInterface dialog, int which) { 161 | if (!TextUtils.isEmpty(et.getText())) { 162 | File file = new File(path, et.getText().toString()); 163 | if (!file.exists()) { 164 | if (file.mkdirs()) { 165 | //创建文件夹成功,刷新目录显示 166 | MainActivity.this.refreshDirectory(path, true); 167 | Toast.makeText(MainActivity.this, getString(R.string.str_folder_create_success), Toast.LENGTH_SHORT).show(); 168 | } else { 169 | Toast.makeText(MainActivity.this, getString(R.string.str_folder_create_failed), Toast.LENGTH_SHORT).show(); 170 | } 171 | } else { 172 | //文件夹已经存在 173 | Toast.makeText(MainActivity.this, getString(R.string.str_folder_exist), Toast.LENGTH_SHORT).show(); 174 | } 175 | } 176 | } 177 | }) 178 | .setNegativeButton(MainActivity.this.getString(R.string.str_cancel), null) 179 | .show(); 180 | } 181 | 182 | @Override 183 | public void showHideFolder(String path, boolean showHideFile) { 184 | MainActivity.this.closeMenu(operationMenuPopupWindow); 185 | refreshDirectory(path, !showHideFile); 186 | } 187 | }); 188 | } 189 | 190 | /** 191 | * 展示排序方式菜单 192 | */ 193 | private void showSortMethodMenu() { 194 | final SortMenuPopupWindow sortMenuPopupWindow = new SortMenuPopupWindow(this.getSupportFragmentManager().getFragments().get(mCurrentFragmentPosition)); 195 | sortMenuPopupWindow.showAtLocation(findViewById(R.id.id_main_activity), Gravity.TOP, 0, 0); 196 | sortMenuPopupWindow.setOnSortItemClickListener(new SortMenuPopupWindow.OnSortItemClickListener() { 197 | @Override 198 | public void closeMenu() { 199 | MainActivity.this.closeMenu(sortMenuPopupWindow); 200 | } 201 | 202 | @Override 203 | public void sortByName(String path) { 204 | MainActivity.this.closeMenu(sortMenuPopupWindow); 205 | MainActivity.this.refreshDirectory(path, true); 206 | } 207 | 208 | @Override 209 | public void sortBySizeDesc(String path) { 210 | MainActivity.this.closeMenu(sortMenuPopupWindow); 211 | //从大到小排序 212 | MainActivity.this.refreshDirectory(FileUtils.filterSortFileBySize(path, true), false); 213 | } 214 | 215 | @Override 216 | public void sortBySizeAsc(String path) { 217 | MainActivity.this.closeMenu(sortMenuPopupWindow); 218 | //从大到小排序 219 | MainActivity.this.refreshDirectory(FileUtils.filterSortFileBySize(path, false), false); 220 | } 221 | 222 | @Override 223 | public void sortByModifyDate(String path) { 224 | MainActivity.this.closeMenu(sortMenuPopupWindow); 225 | //从大到小排序 226 | MainActivity.this.refreshDirectory(FileUtils.filterSortFileByLastModifiedTime(path), false); 227 | } 228 | }); 229 | } 230 | 231 | /** 232 | * 关闭隐藏下拉菜单 233 | */ 234 | private void closeMenu(PopupWindow popupWindow) { 235 | if (popupWindow.isShowing()) { 236 | popupWindow.dismiss(); 237 | } 238 | } 239 | 240 | /** 241 | * 刷新目录显示 242 | * @param path 243 | * @param showHideFile 244 | */ 245 | private void refreshDirectory(String path, boolean showHideFile){ 246 | Fragment fragment = MainActivity.this.getSupportFragmentManager() 247 | .getFragments().get(mCurrentFragmentPosition); 248 | if (fragment instanceof FileListFragment) { 249 | FileListFragment fileListFragment = (FileListFragment) fragment; 250 | fileListFragment.showChange(FileUtils.filterSortFileByName(path, showHideFile)); 251 | } 252 | } 253 | 254 | /** 255 | * 刷新目录显示 256 | * @param fileArray 257 | * @param showHideFile 258 | */ 259 | private void refreshDirectory(File[] fileArray, boolean showHideFile){ 260 | Fragment fragment = MainActivity.this.getSupportFragmentManager() 261 | .getFragments().get(mCurrentFragmentPosition); 262 | if (fragment instanceof FileListFragment) { 263 | FileListFragment fileListFragment = (FileListFragment) fragment; 264 | fileListFragment.showChange(fileArray); 265 | } 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/adapter/CommonAdapter.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.adapter; 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 | /** 12 | * Created by szh on 2017/2/13. 13 | */ 14 | 15 | public abstract class CommonAdapter extends BaseAdapter { 16 | protected LayoutInflater mInflater; 17 | protected Context mContext; 18 | protected List mDatas; 19 | protected final int mItemLayoutId; 20 | 21 | public CommonAdapter(Context context, List mDatas, int itemLayoutId) 22 | { 23 | this.mContext = context; 24 | this.mInflater = LayoutInflater.from(mContext); 25 | this.mDatas = mDatas; 26 | this.mItemLayoutId = itemLayoutId; 27 | } 28 | 29 | @Override 30 | public int getCount() 31 | { 32 | return mDatas.size(); 33 | } 34 | 35 | @Override 36 | public T getItem(int position) 37 | { 38 | return mDatas.get(position); 39 | } 40 | 41 | @Override 42 | public long getItemId(int position) 43 | { 44 | return position; 45 | } 46 | 47 | @Override 48 | public View getView(int position, View convertView, ViewGroup parent) 49 | { 50 | final ViewHolder viewHolder = getViewHolder(position, convertView, 51 | parent); 52 | convert(viewHolder, getItem(position)); 53 | return viewHolder.getConvertView(); 54 | 55 | } 56 | 57 | public abstract void convert(ViewHolder helper, T item); 58 | 59 | private ViewHolder getViewHolder(int position, View convertView, 60 | ViewGroup parent) 61 | { 62 | return ViewHolder.get(mContext, convertView, parent, mItemLayoutId, 63 | position); 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/adapter/FileListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.adapter; 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 | import android.widget.ImageButton; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.codekong.fileexplorer.R; 13 | import com.codekong.fileexplorer.util.FileUtils; 14 | 15 | import java.io.File; 16 | import java.util.List; 17 | 18 | import butterknife.BindView; 19 | import butterknife.ButterKnife; 20 | 21 | /** 22 | * Created by szh on 2017/2/8. 23 | */ 24 | 25 | public class FileListAdapter extends BaseAdapter { 26 | private Context mContext; 27 | private List mFileList; 28 | 29 | public FileListAdapter(Context context, List fileList) { 30 | this.mContext = context; 31 | this.mFileList = fileList; 32 | } 33 | 34 | @Override 35 | public int getCount() { 36 | return mFileList.size(); 37 | } 38 | 39 | @Override 40 | public File getItem(int position) { 41 | return mFileList.get(position); 42 | } 43 | 44 | @Override 45 | public long getItemId(int position) { 46 | return position; 47 | } 48 | 49 | @Override 50 | public View getView(int position, View convertView, ViewGroup parent) { 51 | File file = mFileList.get(position); 52 | FileViewHolder viewHolder; 53 | if (convertView == null) { 54 | convertView = LayoutInflater.from(mContext).inflate(R.layout.file_item, null); 55 | viewHolder = new FileViewHolder(convertView); 56 | convertView.setTag(viewHolder); 57 | } else { 58 | viewHolder = (FileViewHolder) convertView.getTag(); 59 | } 60 | 61 | if (file.isDirectory()) { 62 | viewHolder.fileSize.setText(R.string.str_folder); 63 | viewHolder.fileIcon.setImageResource(R.drawable.ic_folder); 64 | viewHolder.nextDir.setVisibility(View.VISIBLE); 65 | } else { 66 | viewHolder.fileSize.setText(FileUtils.getFileSize(file)); 67 | viewHolder.fileIcon.setImageResource(R.drawable.ic_file); 68 | viewHolder.nextDir.setVisibility(View.GONE); 69 | } 70 | 71 | viewHolder.fileDate.setText(FileUtils.getFileDate(file)); 72 | viewHolder.fileName.setText(file.getName()); 73 | 74 | return convertView; 75 | } 76 | 77 | 78 | public void updateFileList(List fileList) { 79 | this.mFileList = fileList; 80 | notifyDataSetChanged(); 81 | } 82 | 83 | class FileViewHolder { 84 | @BindView(R.id.id_file_icon) 85 | ImageView fileIcon; 86 | @BindView(R.id.id_file_name) 87 | TextView fileName; 88 | @BindView(R.id.id_file_size) 89 | TextView fileSize; 90 | @BindView(R.id.id_file_date) 91 | TextView fileDate; 92 | @BindView(R.id.id_next_dir) 93 | ImageButton nextDir; 94 | 95 | FileViewHolder(View view) { 96 | ButterKnife.bind(this, view); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/adapter/SwitchViewPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | 8 | import com.codekong.fileexplorer.R; 9 | import com.codekong.fileexplorer.fragment.FileCategoryFragment; 10 | import com.codekong.fileexplorer.fragment.FileListFragment; 11 | 12 | /** 13 | * Created by szh on 2017/2/9. 14 | */ 15 | 16 | public class SwitchViewPagerAdapter extends FragmentPagerAdapter { 17 | private int mCurrentPosition = 0; 18 | private String[] mTabName = new String[2]; 19 | public SwitchViewPagerAdapter(Context context, FragmentManager fm) { 20 | super(fm); 21 | mTabName[0] = context.getString(R.string.str_category); 22 | mTabName[1] = context.getString(R.string.str_phone); 23 | } 24 | 25 | @Override 26 | public Fragment getItem(int position) { 27 | if (position == 1){ 28 | mCurrentPosition = 1; 29 | return new FileListFragment(); 30 | } 31 | mCurrentPosition = 0; 32 | return new FileCategoryFragment(); 33 | } 34 | 35 | @Override 36 | public int getCount() { 37 | return mTabName.length; 38 | } 39 | 40 | @Override 41 | public CharSequence getPageTitle(int position) { 42 | return mTabName[position]; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/adapter/ViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.adapter; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.util.SparseArray; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | /** 13 | * Created by szh on 2017/2/13. 14 | */ 15 | 16 | public class ViewHolder 17 | { 18 | private final SparseArray mViews; 19 | private int mPosition; 20 | private View mConvertView; 21 | 22 | private ViewHolder(Context context, ViewGroup parent, int layoutId, 23 | int position) 24 | { 25 | this.mPosition = position; 26 | this.mViews = new SparseArray(); 27 | mConvertView = LayoutInflater.from(context).inflate(layoutId, parent, 28 | false); 29 | // setTag 30 | mConvertView.setTag(this); 31 | } 32 | 33 | /** 34 | * 拿到一个ViewHolder对象 35 | * 36 | * @param context 37 | * @param convertView 38 | * @param parent 39 | * @param layoutId 40 | * @param position 41 | * @return 42 | */ 43 | public static ViewHolder get(Context context, View convertView, 44 | ViewGroup parent, int layoutId, int position) 45 | { 46 | if (convertView == null) 47 | { 48 | return new ViewHolder(context, parent, layoutId, position); 49 | } 50 | return (ViewHolder) convertView.getTag(); 51 | } 52 | 53 | public View getConvertView() 54 | { 55 | return mConvertView; 56 | } 57 | 58 | /** 59 | * 通过控件的Id获取对于的控件,如果没有则加入views 60 | * 61 | * @param viewId 62 | * @return 63 | */ 64 | public T getView(int viewId) 65 | { 66 | View view = mViews.get(viewId); 67 | if (view == null) 68 | { 69 | view = mConvertView.findViewById(viewId); 70 | mViews.put(viewId, view); 71 | } 72 | return (T) view; 73 | } 74 | 75 | /** 76 | * 为TextView设置字符串 77 | * 78 | * @param viewId 79 | * @param text 80 | * @return 81 | */ 82 | public ViewHolder setText(int viewId, String text) 83 | { 84 | TextView view = getView(viewId); 85 | view.setText(text); 86 | return this; 87 | } 88 | 89 | /** 90 | * 为ImageView设置图片 91 | * 92 | * @param viewId 93 | * @param drawableId 94 | * @return 95 | */ 96 | public ViewHolder setImageResource(int viewId, int drawableId) 97 | { 98 | ImageView view = getView(viewId); 99 | view.setImageResource(drawableId); 100 | 101 | return this; 102 | } 103 | 104 | /** 105 | * 为ImageView设置图片 106 | * 107 | * @param viewId 108 | * @param bm 109 | * @return 110 | */ 111 | public ViewHolder setImageBitmap(int viewId, Bitmap bm) 112 | { 113 | ImageView view = getView(viewId); 114 | view.setImageBitmap(bm); 115 | return this; 116 | } 117 | 118 | public int getPosition() 119 | { 120 | return mPosition; 121 | } 122 | 123 | } -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/bean/Category.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.bean; 2 | 3 | /** 4 | * Created by szh on 2017/2/13. 5 | * 分类Bean 6 | */ 7 | 8 | public class Category { 9 | //每种类别的图标名称 10 | private String mCategoryIcon; 11 | //每种类别的名称 12 | private String mCategoryName; 13 | //每种类别下的项目数目 14 | private String mCategoryNums; 15 | 16 | public String getCategoryIcon() { 17 | return mCategoryIcon; 18 | } 19 | 20 | public void setCategoryIcon(String mCategoryIcon) { 21 | this.mCategoryIcon = mCategoryIcon; 22 | } 23 | 24 | public String getCategoryName() { 25 | return mCategoryName; 26 | } 27 | 28 | public void setCategoryName(String mCategoryName) { 29 | this.mCategoryName = mCategoryName; 30 | } 31 | 32 | public String getCategoryNums() { 33 | return mCategoryNums; 34 | } 35 | 36 | public void setCategoryNums(String mCategoryNums) { 37 | this.mCategoryNums = mCategoryNums; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/config/Constant.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.config; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * Created by szh on 2017/2/9.] 10 | * 常量表 11 | */ 12 | 13 | public class Constant { 14 | /*************************文件排序方式(文件夹在前,文件在后)****************************/ 15 | //按文件名和文件大小排序时,文件夹按照数字在前,字母在后的顺序先排序,再按文件的具体要求排序 16 | //文件名 17 | public static final int SORT_BY_FILE_NAME = 1; 18 | //文件大小(从小到大) 19 | public static final int SORT_BY_FILE_SIZE_ASC = 2; 20 | //文件大小(从大到小) 21 | public static final int SORT_BY_FILE_SIZE_DESC = 3; 22 | //文件类型(将文件后缀相同的排列到一起,后缀按数字字母顺序排列) 23 | public static final int SORT_BY_FILE_TYPE = 4; 24 | //文件修改时间 25 | public static final int SORT_BY_FILE_MIDIFY_TIME = 4; 26 | /*************************文件排序方式****************************/ 27 | 28 | /*************************文件分类****************************/ 29 | public static final String[] FILE_CATEGORY_NAME = {"视频", "文档", "图片", "音乐", "安装包", "压缩包"}; 30 | 31 | public static final String[] FILE_CATEGORY_ICON = {"ic_video", "ic_document", "ic_picture", "ic_music", 32 | "ic_apk", "ic_zip"}; 33 | /*************************文件分类****************************/ 34 | 35 | //每种类型的文件包含的后缀 36 | public static final Map> CATEGORY_SUFFIX; 37 | 38 | static { 39 | //初始化赋值 40 | CATEGORY_SUFFIX = new HashMap<>(FILE_CATEGORY_ICON.length); 41 | Set set = new HashSet<>(); 42 | set.add("mp4"); 43 | set.add("avi"); 44 | set.add("wmv"); 45 | set.add("flv"); 46 | CATEGORY_SUFFIX.put("video", set); 47 | 48 | set.add("txt"); 49 | set.add("pdf"); 50 | set.add("doc"); 51 | set.add("docx"); 52 | set.add("xls"); 53 | set.add("xlsx"); 54 | CATEGORY_SUFFIX.put("document", set); 55 | 56 | set = new HashSet<>(); 57 | set.add("jpg"); 58 | set.add("jpeg"); 59 | set.add("png"); 60 | set.add("bmp"); 61 | set.add("gif"); 62 | CATEGORY_SUFFIX.put("picture", set); 63 | 64 | set = new HashSet<>(); 65 | set.add("mp3"); 66 | set.add("ogg"); 67 | CATEGORY_SUFFIX.put("music", set); 68 | 69 | set = new HashSet<>(); 70 | set.add("apk"); 71 | CATEGORY_SUFFIX.put("apk", set); 72 | 73 | set = new HashSet<>(); 74 | set.add("zip"); 75 | set.add("rar"); 76 | set.add("7z"); 77 | CATEGORY_SUFFIX.put("zip", set); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/fragment/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | /** 11 | * Created by 尚振鸿 on 17-12-15. 22:14 12 | * mail:szh@codekong.cn 13 | */ 14 | 15 | public abstract class BaseFragment extends Fragment { 16 | //Fragment的View加载完毕的标记 17 | private boolean isViewCreated; 18 | //Fragment对用户可见的标记 19 | private boolean isUIVisible; 20 | 21 | @Override 22 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 23 | return super.onCreateView(inflater, container, savedInstanceState); 24 | } 25 | 26 | @Override 27 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 28 | super.onViewCreated(view, savedInstanceState); 29 | isViewCreated = true; 30 | lazyLoad(); 31 | } 32 | 33 | @Override 34 | public void setUserVisibleHint(boolean isVisibleToUser) { 35 | super.setUserVisibleHint(isVisibleToUser); 36 | //isVisibleToUser这个boolean值表示:该Fragment的UI 用户是否可见 37 | if (isVisibleToUser) { 38 | isUIVisible = true; 39 | lazyLoad(); 40 | } else { 41 | isUIVisible = false; 42 | } 43 | } 44 | 45 | private void lazyLoad() { 46 | //这里进行双重标记判断,是因为setUserVisibleHint会多次回调,并且会在onCreateView执行前回调,必须确保onCreateView加载完毕且页面可见,才加载数据 47 | if (isViewCreated && isUIVisible) { 48 | loadData(); 49 | //数据加载完毕,恢复标记,防止重复加载 50 | isViewCreated = false; 51 | isUIVisible = false; 52 | } 53 | } 54 | 55 | 56 | protected abstract void loadData(); 57 | 58 | 59 | @Override 60 | public void onDestroyView() { 61 | super.onDestroyView(); 62 | //页面销毁,恢复标记 63 | isViewCreated = false; 64 | isUIVisible = false; 65 | } 66 | } -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/fragment/FileCategoryFragment.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.fragment; 2 | 3 | import android.Manifest; 4 | import android.os.Bundle; 5 | import android.os.Environment; 6 | import android.os.Handler; 7 | import android.os.Looper; 8 | import android.os.Message; 9 | import android.support.annotation.Nullable; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.FrameLayout; 14 | import android.widget.GridView; 15 | import android.widget.TextView; 16 | 17 | import com.codekong.fileexplorer.R; 18 | import com.codekong.fileexplorer.adapter.CommonAdapter; 19 | import com.codekong.fileexplorer.adapter.ViewHolder; 20 | import com.codekong.fileexplorer.bean.Category; 21 | import com.codekong.fileexplorer.config.Constant; 22 | import com.codekong.fileexplorer.util.ScanFileCountUtil; 23 | import com.jwenfeng.library.pulltorefresh.BaseRefreshListener; 24 | import com.jwenfeng.library.pulltorefresh.PullToRefreshLayout; 25 | 26 | import java.util.ArrayList; 27 | import java.util.Collections; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.concurrent.ExecutorService; 31 | import java.util.concurrent.Executors; 32 | 33 | import butterknife.BindView; 34 | import butterknife.ButterKnife; 35 | import pub.devrel.easypermissions.AppSettingsDialog; 36 | import pub.devrel.easypermissions.EasyPermissions; 37 | 38 | /** 39 | * Created by szh on 2017/2/9. 40 | * 文件类别Fragment 41 | */ 42 | 43 | public class FileCategoryFragment extends BaseFragment implements EasyPermissions.PermissionCallbacks { 44 | private static final int REQUEST_CODE_EXTERNAL_STORAGE = 0X01; 45 | 46 | @BindView(R.id.id_start_search) 47 | TextView mStartSearchBtn; 48 | @BindView(R.id.id_category_grid_view) 49 | GridView mCategoryGridView; 50 | @BindView(R.id.id_loading_framelayout) 51 | FrameLayout mLoadingFrameLayout; 52 | @BindView(R.id.id_file_category_pulltorefresh) 53 | PullToRefreshLayout mPullToRefreshLayout; 54 | 55 | //存放分类数据 56 | private List mCategoryData = new ArrayList<>(); 57 | 58 | //文件扫描结束的处理 59 | private Handler mHandler = new Handler(Looper.getMainLooper()){ 60 | @Override 61 | public void handleMessage(Message msg) { 62 | mCategoryData.clear(); 63 | mPullToRefreshLayout.finishRefresh(); 64 | Map countRes = (Map) msg.obj; 65 | for (int i = 0; i < Constant.FILE_CATEGORY_ICON.length; i++) { 66 | Category category = new Category(); 67 | category.setCategoryIcon(Constant.FILE_CATEGORY_ICON[i]); 68 | category.setCategoryName(Constant.FILE_CATEGORY_NAME[i]); 69 | category.setCategoryNums(countRes.get(Constant.FILE_CATEGORY_ICON[i].substring(3)) + "项"); 70 | mCategoryData.add(category); 71 | } 72 | mLoadingFrameLayout.setVisibility(View.GONE); 73 | setData(); 74 | } 75 | }; 76 | 77 | @Override 78 | public void onCreate(@Nullable Bundle savedInstanceState) { 79 | super.onCreate(savedInstanceState); 80 | } 81 | 82 | @Nullable 83 | @Override 84 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 85 | View view = inflater.inflate(R.layout.fragment_file_category, container, false); 86 | ButterKnife.bind(this, view); 87 | return view; 88 | } 89 | 90 | @Override 91 | protected void loadData() { 92 | if (!EasyPermissions.hasPermissions(FileCategoryFragment.this.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)){ 93 | EasyPermissions.requestPermissions(this,"需要读取文件目录", 94 | REQUEST_CODE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE); 95 | }else { 96 | //已经授权 97 | initEvent(); 98 | //扫描文件 99 | scanFile(); 100 | } 101 | } 102 | 103 | @Override 104 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 105 | super.onActivityCreated(savedInstanceState); 106 | } 107 | 108 | /** 109 | * 初始化事件 110 | */ 111 | private void initEvent() { 112 | mPullToRefreshLayout.setCanLoadMore(false); 113 | mPullToRefreshLayout.setRefreshListener(new BaseRefreshListener() { 114 | @Override 115 | public void refresh() { 116 | scanFile(); 117 | } 118 | 119 | @Override 120 | public void loadMore() { 121 | 122 | } 123 | }); 124 | } 125 | 126 | /** 127 | * 设置数据 128 | */ 129 | private void setData() { 130 | CommonAdapter mAdapter = new CommonAdapter(this.getContext(), mCategoryData, R.layout.category_item) { 131 | @Override 132 | public void convert(ViewHolder helper, Category item) { 133 | helper.setImageResource(R.id.id_category_icon, getResId(item.getCategoryIcon())); 134 | helper.setText(R.id.id_category_name, item.getCategoryName()); 135 | helper.setText(R.id.id_category_nums, item.getCategoryNums()); 136 | } 137 | }; 138 | mCategoryGridView.setAdapter(mAdapter); 139 | } 140 | 141 | @Override 142 | public void onDestroyView() { 143 | super.onDestroyView(); 144 | } 145 | 146 | public int getResId(String iconName){ 147 | return getContext().getResources().getIdentifier(iconName, "drawable", getContext().getPackageName()); 148 | } 149 | 150 | /** 151 | * 扫描文件 152 | */ 153 | private void scanFile(){ 154 | if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ 155 | return; 156 | } 157 | final String path = Environment.getExternalStorageDirectory().getAbsolutePath(); 158 | 159 | //单一线程线程池 160 | ExecutorService singleExecutorService = Executors.newSingleThreadExecutor(); 161 | singleExecutorService.submit(new Runnable() { 162 | @Override 163 | public void run() { 164 | ScanFileCountUtil scanFileCountUtil = new ScanFileCountUtil 165 | .Builder(mHandler) 166 | .setFilePath(path) 167 | .setCategorySuffix(Constant.CATEGORY_SUFFIX) 168 | .create(); 169 | scanFileCountUtil.scanCountFile(); 170 | } 171 | }); 172 | } 173 | 174 | @Override 175 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 176 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 177 | // Forward results to EasyPermissions 178 | EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); 179 | } 180 | 181 | @Override 182 | public void onPermissionsGranted(int requestCode, List perms) { 183 | initEvent(); 184 | //扫描文件 185 | scanFile(); 186 | } 187 | 188 | @Override 189 | public void onPermissionsDenied(int requestCode, List perms) { 190 | if (EasyPermissions.somePermissionPermanentlyDenied(this, 191 | Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE))) { 192 | new AppSettingsDialog.Builder(this).build().show(); 193 | } 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/fragment/FileListFragment.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.fragment; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.support.annotation.Nullable; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.webkit.MimeTypeMap; 12 | import android.widget.AbsListView; 13 | import android.widget.AdapterView; 14 | import android.widget.ListView; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.codekong.fileexplorer.R; 19 | import com.codekong.fileexplorer.adapter.FileListAdapter; 20 | import com.codekong.fileexplorer.util.FileUtils; 21 | import com.jwenfeng.library.pulltorefresh.BaseRefreshListener; 22 | import com.jwenfeng.library.pulltorefresh.PullToRefreshLayout; 23 | 24 | import java.io.File; 25 | import java.lang.reflect.Field; 26 | import java.util.ArrayList; 27 | import java.util.Arrays; 28 | import java.util.Stack; 29 | 30 | import butterknife.BindView; 31 | import butterknife.ButterKnife; 32 | import butterknife.OnClick; 33 | import butterknife.Unbinder; 34 | 35 | /** 36 | * Created by szh on 2017/2/9. 37 | * 文件列表Fragment 38 | */ 39 | 40 | public class FileListFragment extends BaseFragment implements AdapterView.OnItemClickListener { 41 | @BindView(R.id.id_start_search) 42 | TextView mStartSearch; 43 | @BindView(R.id.id_now_file_path_tv) 44 | TextView mNowFilePathTv; 45 | @BindView(R.id.id_file_list_view) 46 | ListView mFileListView; 47 | @BindView(R.id.id_empty_view) 48 | TextView mEmptyView; 49 | @BindView(R.id.id_file_list_pulltorefresh) 50 | PullToRefreshLayout mPullToRefreshLayout; 51 | 52 | private Unbinder mUnbinder; 53 | //文件列表数组 54 | private File[] mFilesArray; 55 | //文件列表List 56 | private ArrayList mFileList = new ArrayList<>(); 57 | //文件ListView适配器 58 | private FileListAdapter mFileListAdapter; 59 | //文件根路径 60 | private String mRootPath; 61 | //当前的文件路径堆栈 62 | public static Stack mNowPathStack; 63 | 64 | @Override 65 | public void onCreate(@Nullable Bundle savedInstanceState) { 66 | super.onCreate(savedInstanceState); 67 | } 68 | 69 | @Nullable 70 | @Override 71 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 72 | View view = inflater.inflate(R.layout.fragment_file_list, container, false); 73 | mUnbinder = ButterKnife.bind(this, view); 74 | return view; 75 | } 76 | 77 | @Override 78 | protected void loadData() { 79 | initEvent(); 80 | initData(); 81 | } 82 | 83 | @Override 84 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 85 | super.onActivityCreated(savedInstanceState); 86 | } 87 | 88 | /** 89 | * 初始化事件 90 | */ 91 | private void initEvent() { 92 | mFileListView.setOnScrollListener(new AbsListView.OnScrollListener() { 93 | @Override 94 | public void onScrollStateChanged(AbsListView absListView, int i) { 95 | 96 | } 97 | 98 | @Override 99 | public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 100 | if (firstVisibleItem != 0){ 101 | disablePullToRefresh(mPullToRefreshLayout, false); 102 | }else{ 103 | disablePullToRefresh(mPullToRefreshLayout, true); 104 | } 105 | } 106 | }); 107 | 108 | mPullToRefreshLayout.setCanLoadMore(false); 109 | mPullToRefreshLayout.setRefreshListener(new BaseRefreshListener() { 110 | @Override 111 | public void refresh() { 112 | initData(); 113 | mPullToRefreshLayout.finishRefresh(); 114 | } 115 | 116 | @Override 117 | public void loadMore() { 118 | 119 | } 120 | }); 121 | } 122 | 123 | 124 | /** 125 | * 初始化数据并显示 126 | */ 127 | private void initData() { 128 | String fileNowPath = ""; 129 | //对文件进行过滤和排序 130 | mFilesArray = FileUtils.filterSortFileByName(Environment.getExternalStorageDirectory().getPath(), true); 131 | mFileList.clear(); 132 | mFileList.addAll(Arrays.asList(mFilesArray)); 133 | mRootPath = Environment.getExternalStorageDirectory().getPath(); 134 | mNowPathStack = new Stack<>(); 135 | mNowPathStack.push(mRootPath); 136 | fileNowPath = FileUtils.getNowStackPathString(mNowPathStack); 137 | //设置文件路径显示 138 | mNowFilePathTv.setText(fileNowPath); 139 | mFileListAdapter = new FileListAdapter(this.getContext(), mFileList); 140 | mFileListView.setAdapter(mFileListAdapter); 141 | mFileListView.setOnItemClickListener(this); 142 | //设置没有item显示时默认显示的图标 143 | mFileListView.setEmptyView(mEmptyView); 144 | } 145 | 146 | 147 | @Override 148 | public void onDestroyView() { 149 | super.onDestroyView(); 150 | mUnbinder.unbind(); 151 | } 152 | 153 | @Override 154 | public void onItemClick(AdapterView adapterView, View view, int position, long id) { 155 | File file = mFileList.get(position); 156 | String fileName = file.getName(); 157 | if (file.isFile()) { 158 | //如果是File则打开 159 | Intent intent = new Intent(); 160 | intent.setAction(Intent.ACTION_VIEW); 161 | Uri data = Uri.fromFile(file); 162 | int index = fileName.lastIndexOf("."); 163 | String suffix = fileName.substring(index + 1); 164 | String type = MimeTypeMap.getSingleton().getExtensionFromMimeType(suffix); 165 | if (type == null) { 166 | Toast.makeText(getContext(), R.string.str_no_program_can_open_the_file, Toast.LENGTH_SHORT).show(); 167 | return; 168 | } 169 | intent.setDataAndType(data, type); 170 | startActivity(intent); 171 | } else { 172 | //是目录则进入下级目录 173 | mNowPathStack.push("/" + fileName); 174 | showChange(FileUtils.getNowStackPathString(mNowPathStack)); 175 | } 176 | } 177 | 178 | /** 179 | * 改变数据源,刷新列表 180 | */ 181 | public void showChange(String path) { 182 | mNowFilePathTv.setText(path); 183 | mFilesArray = FileUtils.filterSortFileByName(path, true); 184 | mFileList.clear(); 185 | mFileList.addAll(Arrays.asList(mFilesArray)); 186 | mFileListAdapter.updateFileList(mFileList); 187 | } 188 | 189 | /** 190 | * 改变数据源,刷新列表 191 | */ 192 | public void showChange(File[] fileArray) { 193 | mFilesArray = fileArray; 194 | mFileList.clear(); 195 | mFileList.addAll(Arrays.asList(mFilesArray)); 196 | mFileListAdapter.updateFileList(mFileList); 197 | } 198 | 199 | @OnClick(R.id.id_now_file_path_tv) 200 | public void onViewClicked() { 201 | //点击返回上级目录 202 | if (!mNowPathStack.empty()){ 203 | if (mNowPathStack.peek().equals(Environment.getExternalStorageDirectory().getPath())){ 204 | return; 205 | } 206 | mNowPathStack.pop(); 207 | } 208 | showChange(FileUtils.getNowStackPathString(mNowPathStack)); 209 | } 210 | 211 | /** 212 | * 通过反射禁用下拉刷新 213 | * @param disable 214 | */ 215 | private void disablePullToRefresh(PullToRefreshLayout pullToRefreshLayout, boolean disable){ 216 | Class pullToRefreshClass = PullToRefreshLayout.class; 217 | try { 218 | Field canRefreshField = pullToRefreshClass.getDeclaredField("canRefresh"); 219 | canRefreshField.setAccessible(true); 220 | canRefreshField.set(pullToRefreshLayout, disable); 221 | canRefreshField.setAccessible(false); 222 | } catch (NoSuchFieldException e) { 223 | e.printStackTrace(); 224 | } catch (IllegalAccessException e) { 225 | e.printStackTrace(); 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/listener/OnClickMenuListener.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.listener; 2 | 3 | import android.view.View; 4 | 5 | import com.codekong.fileexplorer.R; 6 | 7 | /** 8 | * Created by szh on 2017/2/10. 9 | */ 10 | 11 | public class OnClickMenuListener implements View.OnClickListener { 12 | 13 | @Override 14 | public void onClick(View view) { 15 | switch ((int)view.getTag()){ 16 | case (R.layout.operation_popup_window_menu + 111): 17 | break; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/util/BackHandlerHelper.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.util; 2 | 3 | /** 4 | * Created by szh on 2017/2/10. 5 | */ 6 | 7 | public class BackHandlerHelper { 8 | public static boolean handleBackPress(){ 9 | 10 | return false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.util; 2 | 3 | import java.io.File; 4 | import java.io.FileFilter; 5 | import java.text.DateFormat; 6 | import java.text.SimpleDateFormat; 7 | import java.util.Arrays; 8 | import java.util.Comparator; 9 | import java.util.Date; 10 | import java.util.Locale; 11 | import java.util.Stack; 12 | 13 | /** 14 | * Created by szh on 2017/2/8. 15 | */ 16 | 17 | public class FileUtils { 18 | //文件大小 19 | private static final long KB = 2 << 9; 20 | private static final long MB = 2 << 19; 21 | private static final long GB = 2 << 29; 22 | 23 | //日期格式化 24 | private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); 25 | //当前路径 26 | private static String mNowPath; 27 | private static Stack mNowPathStack; 28 | 29 | /** 30 | * 获得指定文件的大小 31 | * 32 | * @param file 33 | * @return 34 | */ 35 | public static String getFileSize(File file) { 36 | if (file.isFile()) { 37 | long fileLength = file.length(); 38 | if (fileLength < KB) { 39 | return fileLength + "B"; 40 | } else if (fileLength < MB) { 41 | return String.format(Locale.getDefault(), "%.2fKB", fileLength / (double) KB); 42 | } else if (fileLength < GB) { 43 | return String.format(Locale.getDefault(), "%.2fMB", fileLength / (double) MB); 44 | } else { 45 | return String.format(Locale.getDefault(), "%.2fGB", fileLength / (double) GB); 46 | } 47 | } 48 | return null; 49 | } 50 | 51 | /** 52 | * 获得文件最近修改的时间 53 | * 54 | * @param file 55 | * @return 56 | */ 57 | public static String getFileDate(File file) { 58 | return dateFormat.format(new Date(file.lastModified())); 59 | } 60 | 61 | /** 62 | * 获得当前所在的路径栈的字符串表示 63 | * 64 | * @return 65 | */ 66 | public static String getNowStackPathString(Stack nowPathStack) { 67 | mNowPathStack = nowPathStack; 68 | String result = ""; 69 | Stack temp = new Stack<>(); 70 | temp.addAll(nowPathStack); 71 | while (temp.size() != 0) { 72 | result = temp.pop() + result; 73 | } 74 | mNowPath = result; 75 | return result; 76 | } 77 | 78 | /** 79 | * 获得当前路径 80 | * 81 | * @return 82 | */ 83 | public static String getNowPath() { 84 | return mNowPath; 85 | } 86 | 87 | /** 88 | * 返回上级目录 89 | * 90 | * @return 91 | */ 92 | public static String returnToParentDir() { 93 | mNowPathStack.pop(); 94 | return mNowPath; 95 | } 96 | 97 | /** 98 | * 过滤隐藏文件,并按字母序排序文件目录和文件 99 | * 100 | * @param path 101 | * @return 102 | */ 103 | public static File[] filterSortFileByName(String path, boolean isHideFile) { 104 | 105 | File[] fileArray = null; 106 | if (isHideFile) { 107 | //不显示隐藏文件 108 | fileArray = new File(path).listFiles(new FileFilter() { 109 | @Override 110 | public boolean accept(File file) { 111 | //过滤掉隐藏文件 112 | return !file.getName().startsWith("."); 113 | } 114 | }); 115 | } else { 116 | //显示隐藏文件 117 | fileArray = new File(path).listFiles(); 118 | } 119 | 120 | //文件排序 121 | Arrays.sort(fileArray, new Comparator() { 122 | @Override 123 | public int compare(File file, File t1) { 124 | if (file.isDirectory() && t1.isFile()) { 125 | return -1; 126 | } else if (file.isFile() && t1.isDirectory()) { 127 | return 1; 128 | } 129 | return file.getName().compareToIgnoreCase(t1.getName()); 130 | } 131 | }); 132 | return fileArray; 133 | } 134 | 135 | 136 | /** 137 | * 过滤隐藏文件,并按文件大小排序 138 | * 139 | * @param path 140 | * @param desc 141 | * @return 142 | */ 143 | public static File[] filterSortFileBySize(String path, final boolean desc) { 144 | 145 | //不显示隐藏文件 146 | File[] fileArray = new File(path).listFiles(new FileFilter() { 147 | @Override 148 | public boolean accept(File file) { 149 | //过滤掉隐藏文件 150 | return !file.getName().startsWith("."); 151 | } 152 | }); 153 | //文件排序 154 | Arrays.sort(fileArray, new Comparator() { 155 | @Override 156 | public int compare(File file, File t1) { 157 | if (file.isDirectory() && t1.isFile()) { 158 | return -1; 159 | } else if (file.isFile() && t1.isDirectory()) { 160 | return 1; 161 | } else if (file.isFile() && t1.isFile()) { 162 | if (desc) { 163 | return file.length() - t1.length() > 0 ? -1 : 1; 164 | } else { 165 | return file.length() - t1.length() > 0 ? 1 : -1; 166 | } 167 | } 168 | return file.getName().compareToIgnoreCase(t1.getName()); 169 | } 170 | }); 171 | return fileArray; 172 | } 173 | 174 | /** 175 | * 按文件修改时间排序 176 | * 177 | * @param path 178 | * @return 179 | */ 180 | public static File[] filterSortFileByLastModifiedTime(String path) { 181 | 182 | //不显示隐藏文件 183 | File[] fileArray = new File(path).listFiles(new FileFilter() { 184 | @Override 185 | public boolean accept(File file) { 186 | //过滤掉隐藏文件 187 | return !file.getName().startsWith("."); 188 | } 189 | }); 190 | //文件排序 191 | Arrays.sort(fileArray, new Comparator() { 192 | @Override 193 | public int compare(File file, File t1) { 194 | if (file.isDirectory() && t1.isFile()) { 195 | return -1; 196 | } else if (file.isFile() && t1.isDirectory()) { 197 | return 1; 198 | } else if (file.isFile() && t1.isFile() || (file.isDirectory() && t1.isDirectory())) { 199 | //最新的文件排在最前面 200 | return file.lastModified() - t1.lastModified() > 0 ? -1 : 1; 201 | } 202 | return file.getName().compareToIgnoreCase(t1.getName()); 203 | } 204 | }); 205 | return fileArray; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/util/FragmentBackHandlerInterface.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.util; 2 | 3 | /** 4 | * Created by szh on 2017/2/10. 5 | */ 6 | 7 | public interface FragmentBackHandlerInterface { 8 | boolean onBackPressed(); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/util/ScanFileCountUtil.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.util; 2 | 3 | import android.os.Handler; 4 | import android.os.Message; 5 | 6 | import java.io.File; 7 | import java.io.FilenameFilter; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Set; 12 | import java.util.concurrent.ConcurrentHashMap; 13 | import java.util.concurrent.ConcurrentLinkedQueue; 14 | import java.util.concurrent.ExecutorService; 15 | import java.util.concurrent.Executors; 16 | import java.util.concurrent.Semaphore; 17 | import java.util.concurrent.TimeUnit; 18 | 19 | /** 20 | * Created by 尚振鸿 on 17-12-16. 14:26 21 | * mail:szh@codekong.cn 22 | * 扫描文件并统计工具类 23 | */ 24 | 25 | public class ScanFileCountUtil { 26 | //扫描根目录 27 | private String mFilePath; 28 | 29 | //各个分类所对应的文件后缀 30 | private Map> mCategorySuffix; 31 | //最终的统计结果 32 | private ConcurrentHashMap mCountResult; 33 | //用于存储文件目录便于层次遍历 34 | private ConcurrentLinkedQueue mFileConcurrentLinkedQueue; 35 | private Handler mHandler = null; 36 | 37 | public void scanCountFile() { 38 | if (mFilePath == null) { 39 | return; 40 | } 41 | final File file = new File(mFilePath); 42 | 43 | //非目录或者目录不存在直接返回 44 | if (!file.exists() || file.isFile()) { 45 | return; 46 | } 47 | //初始化每个类别的数目为0 48 | for (String category : mCategorySuffix.keySet()) { 49 | //将最后统计结果的key设置为类别 50 | mCountResult.put(category, 0); 51 | } 52 | 53 | //获取到根目录下的文件和文件夹 54 | final File[] files = file.listFiles(new FilenameFilter() { 55 | @Override 56 | public boolean accept(File file, String s) { 57 | //过滤掉隐藏文件 58 | return !file.getName().startsWith("."); 59 | } 60 | }); 61 | 62 | List runnableList = new ArrayList<>(); 63 | //创建信号量(最多同时有10个线程可以访问) 64 | final Semaphore semaphore = new Semaphore(100); 65 | for (File f : files) { 66 | if (f.isDirectory()) { 67 | //把目录添加进队列 68 | mFileConcurrentLinkedQueue.offer(f); 69 | Runnable runnable = new Runnable() { 70 | @Override 71 | public void run() { 72 | countFile(); 73 | } 74 | }; 75 | runnableList.add(runnable); 76 | } else { 77 | //找到该文件所属的类别 78 | for (Map.Entry> entry : mCategorySuffix.entrySet()) { 79 | //获取文件后缀 80 | String suffix = f.getName().substring(f.getName().indexOf(".") + 1).toLowerCase(); 81 | //找到了 82 | if (entry.getValue().contains(suffix)) { 83 | mCountResult.put(entry.getKey(), mCountResult.get(entry.getKey()) + 1); 84 | break; 85 | } 86 | } 87 | } 88 | } 89 | 90 | //固定数目线程池(最大线程数目为cpu核心数,多余线程放在等待队列中) 91 | final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); 92 | for (Runnable runnable : runnableList) { 93 | executorService.submit(runnable); 94 | } 95 | executorService.shutdown(); 96 | //等待线程池中的所有线程运行完成 97 | while (true) { 98 | if (executorService.isTerminated()) { 99 | break; 100 | } 101 | try { 102 | TimeUnit.SECONDS.sleep(1); 103 | } catch (InterruptedException e) { 104 | e.printStackTrace(); 105 | } 106 | } 107 | //传递统计数据给UI界面 108 | Message msg = Message.obtain(); 109 | msg.obj = mCountResult; 110 | mHandler.sendMessage(msg); 111 | } 112 | 113 | /** 114 | * 统计各类型文件数目 115 | */ 116 | private void countFile() { 117 | //对目录进行层次遍历 118 | while (!mFileConcurrentLinkedQueue.isEmpty()) { 119 | //队头出队列 120 | final File tmpFile = mFileConcurrentLinkedQueue.poll(); 121 | final File[] fileArray = tmpFile.listFiles(new FilenameFilter() { 122 | @Override 123 | public boolean accept(File file, String s) { 124 | //过滤掉隐藏文件 125 | return !file.getName().startsWith("."); 126 | } 127 | }); 128 | 129 | for (File f : fileArray) { 130 | if (f.isDirectory()) { 131 | //把目录添加进队列 132 | mFileConcurrentLinkedQueue.offer(f); 133 | } else { 134 | //找到该文件所属的类别 135 | for (Map.Entry> entry : mCategorySuffix.entrySet()) { 136 | //获取文件后缀 137 | String suffix = f.getName().substring(f.getName().indexOf(".") + 1).toLowerCase(); 138 | //找到了 139 | if (entry.getValue().contains(suffix)) { 140 | mCountResult.put(entry.getKey(), mCountResult.get(entry.getKey()) + 1); 141 | break; 142 | } 143 | } 144 | } 145 | } 146 | } 147 | } 148 | 149 | public static class Builder { 150 | private Handler mHandler; 151 | private String mFilePath; 152 | //各个分类所对应的文件后缀 153 | private Map> mCategorySuffix; 154 | 155 | public Builder(Handler handler) { 156 | this.mHandler = handler; 157 | } 158 | 159 | public Builder setFilePath(String filePath) { 160 | this.mFilePath = filePath; 161 | return this; 162 | } 163 | 164 | public Builder setCategorySuffix(Map> categorySuffix) { 165 | this.mCategorySuffix = categorySuffix; 166 | return this; 167 | } 168 | 169 | private void applyConfig(ScanFileCountUtil scanFileCountUtil) { 170 | scanFileCountUtil.mFilePath = mFilePath; 171 | scanFileCountUtil.mCategorySuffix = mCategorySuffix; 172 | scanFileCountUtil.mHandler = mHandler; 173 | scanFileCountUtil.mCountResult = new ConcurrentHashMap(mCategorySuffix.size()); 174 | scanFileCountUtil.mFileConcurrentLinkedQueue = new ConcurrentLinkedQueue<>(); 175 | } 176 | 177 | public ScanFileCountUtil create() { 178 | ScanFileCountUtil scanFileCountUtil = new ScanFileCountUtil(); 179 | applyConfig(scanFileCountUtil); 180 | return scanFileCountUtil; 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/util/ViewUtils.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.util; 2 | 3 | import android.view.Window; 4 | import android.view.WindowManager; 5 | 6 | import java.lang.reflect.Field; 7 | import java.lang.reflect.Method; 8 | 9 | /** 10 | * Created by szh on 2017/2/9. 11 | */ 12 | 13 | public class ViewUtils { 14 | /** 15 | * 设置状态栏字体图标为深色,需要MIUIV6以上 16 | * @param window 需要设置的窗口 17 | * @param dark 是否把状态栏字体及图标颜色设置为深色 18 | * @return boolean 成功执行返回true 19 | * 20 | */ 21 | public static boolean MIUISetStatusBarLightMode(Window window, boolean dark) { 22 | boolean result = false; 23 | if (window != null) { 24 | Class clazz = window.getClass(); 25 | try { 26 | int darkModeFlag = 0; 27 | Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); 28 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); 29 | darkModeFlag = field.getInt(layoutParams); 30 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); 31 | if(dark){ 32 | extraFlagField.invoke(window,darkModeFlag,darkModeFlag);//状态栏透明且黑色字体 33 | }else{ 34 | extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体 35 | } 36 | result=true; 37 | }catch (Exception e){ 38 | 39 | } 40 | } 41 | return result; 42 | } 43 | 44 | /** 45 | * 设置状态栏图标为深色和魅族特定的文字风格,Flyme4.0以上 46 | * 可以用来判断是否为Flyme用户 47 | * @param window 需要设置的窗口 48 | * @param dark 是否把状态栏字体及图标颜色设置为深色 49 | * @return boolean 成功执行返回true 50 | * 51 | */ 52 | public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) { 53 | boolean result = false; 54 | if (window != null) { 55 | try { 56 | WindowManager.LayoutParams lp = window.getAttributes(); 57 | Field darkFlag = WindowManager.LayoutParams.class 58 | .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); 59 | Field meizuFlags = WindowManager.LayoutParams.class 60 | .getDeclaredField("meizuFlags"); 61 | darkFlag.setAccessible(true); 62 | meizuFlags.setAccessible(true); 63 | int bit = darkFlag.getInt(null); 64 | int value = meizuFlags.getInt(lp); 65 | if (dark) { 66 | value |= bit; 67 | } else { 68 | value &= ~bit; 69 | } 70 | meizuFlags.setInt(lp, value); 71 | window.setAttributes(lp); 72 | result = true; 73 | } catch (Exception e) { 74 | 75 | } 76 | } 77 | return result; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/view/HideHeaderListView.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.LayoutInflater; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.widget.ListView; 9 | 10 | import com.codekong.fileexplorer.R; 11 | 12 | /** 13 | * Created by szh on 2017/2/9. 14 | */ 15 | 16 | public class HideHeaderListView extends ListView { 17 | private int mLastY; 18 | private int mOffsetY; 19 | private LayoutInflater mInflater; 20 | public HideHeaderListView(Context context) { 21 | this(context, null); 22 | } 23 | 24 | public HideHeaderListView(Context context, AttributeSet attrs) { 25 | this(context, attrs, 0); 26 | } 27 | 28 | public HideHeaderListView(Context context, AttributeSet attrs, int defStyleAttr) { 29 | super(context, attrs, defStyleAttr); 30 | mInflater = LayoutInflater.from(context); 31 | View headerView = mInflater.inflate(R.layout.item_header, null); 32 | addHeaderView(headerView); 33 | } 34 | 35 | 36 | @Override 37 | public boolean onTouchEvent(MotionEvent ev) { 38 | switch (ev.getAction()){ 39 | case MotionEvent.ACTION_DOWN: 40 | mLastY = (int) ev.getY(); 41 | break; 42 | case MotionEvent.ACTION_MOVE: 43 | mOffsetY = (int) (ev.getY() - mLastY); 44 | break; 45 | default: 46 | } 47 | return false; 48 | // return super.onTouchEvent(ev); 49 | } 50 | 51 | @Override 52 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { 53 | super.onScrollChanged(l, t, oldl, oldt); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/view/OperationMenuPopupWindow.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.view; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.drawable.ColorDrawable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.KeyEvent; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.PopupWindow; 11 | import android.widget.TextView; 12 | 13 | import com.codekong.fileexplorer.R; 14 | 15 | import butterknife.ButterKnife; 16 | import butterknife.OnClick; 17 | 18 | /** 19 | * Created by szh on 2017/2/13. 20 | * 打开选择菜单PopupWindow 21 | */ 22 | 23 | public class OperationMenuPopupWindow extends PopupWindow implements View.OnKeyListener { 24 | private static final String TAG = "OperationMenuPopupWindo"; 25 | private Fragment mFragment; 26 | private View rootView; 27 | private OnWindowItemClickListener onWindowItemClickListener; 28 | //是否正在显示隐藏文件 29 | private static boolean showHideFile = false; 30 | 31 | public OperationMenuPopupWindow(Fragment fragment) { 32 | mFragment = fragment; 33 | LayoutInflater inflater = LayoutInflater.from(mFragment.getContext()); 34 | rootView = inflater.inflate(R.layout.operation_popup_window_menu, null); 35 | TextView textView = rootView.findViewById(R.id.id_action_show_hide_folder); 36 | if (showHideFile){ 37 | //目前隐藏文件是显示的 38 | textView.setText(fragment.getResources().getString(R.string.str_not_show_hidden_file)); 39 | }else{ 40 | textView.setText(fragment.getResources().getString(R.string.str_show_hide_file)); 41 | } 42 | setContentView(rootView); 43 | ButterKnife.bind(this, rootView); 44 | //设置高度和宽度。 45 | this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 46 | this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); 47 | this.setFocusable(true); 48 | //设置动画效果 49 | this.setAnimationStyle(R.style.PopupWindowAnimStyle); 50 | 51 | //当单击Back键或者其他地方使其消失、需要设置这个属性。 52 | rootView.setOnKeyListener(this); 53 | rootView.setFocusable(true); 54 | rootView.setFocusableInTouchMode(true); 55 | //实例化一个ColorDrawable颜色为半透明 56 | ColorDrawable dw = new ColorDrawable(Color.TRANSPARENT); 57 | //设置SelectPicPopupWindow弹出窗体的背景 58 | this.setBackgroundDrawable(dw); 59 | this.setOutsideTouchable(true); 60 | } 61 | 62 | //点back键消失 63 | @Override 64 | public boolean onKey(View v, int keyCode, KeyEvent event) { 65 | if (keyCode == KeyEvent.KEYCODE_BACK && this.isShowing()) { 66 | this.dismiss(); 67 | return true; 68 | } 69 | return false; 70 | } 71 | 72 | public void setOnWindowItemClickListener(OnWindowItemClickListener listener) { 73 | this.onWindowItemClickListener = listener; 74 | } 75 | 76 | @OnClick({R.id.id_close_menu, R.id.id_action_sort, R.id.id_action_new_folder, R.id.id_action_show_hide_folder}) 77 | public void onClick(View view) { 78 | String path = ""; 79 | if (mFragment.getView() != null){ 80 | TextView pathTv = mFragment.getView().findViewById(R.id.id_now_file_path_tv); 81 | path = pathTv.getText().toString(); 82 | } 83 | switch (view.getId()) { 84 | case R.id.id_close_menu: 85 | onWindowItemClickListener.closeMenu(); 86 | break; 87 | case R.id.id_action_sort: 88 | onWindowItemClickListener.sort(path); 89 | break; 90 | case R.id.id_action_new_folder: 91 | onWindowItemClickListener.newFolder(path); 92 | break; 93 | case R.id.id_action_show_hide_folder: 94 | TextView textView = (TextView) view; 95 | if (showHideFile){ 96 | textView.setText(R.string.str_not_show_hidden_file); 97 | }else{ 98 | textView.setText(R.string.str_show_hide_file); 99 | } 100 | showHideFile = !showHideFile; 101 | onWindowItemClickListener.showHideFolder(path, showHideFile); 102 | break; 103 | default: 104 | } 105 | } 106 | 107 | public interface OnWindowItemClickListener { 108 | void closeMenu(); 109 | 110 | void sort(String path); 111 | 112 | void newFolder(String path); 113 | 114 | void showHideFolder(String path, boolean showHideFile); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /app/src/main/java/com/codekong/fileexplorer/view/SortMenuPopupWindow.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.drawable.ColorDrawable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.KeyEvent; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.PopupWindow; 12 | import android.widget.TextView; 13 | 14 | import com.codekong.fileexplorer.R; 15 | 16 | import butterknife.ButterKnife; 17 | import butterknife.OnClick; 18 | 19 | /** 20 | * Created by szh on 2017/2/13. 21 | * 打开选择菜单PopupWindow 22 | */ 23 | 24 | public class SortMenuPopupWindow extends PopupWindow implements View.OnKeyListener { 25 | private Context mContext; 26 | private View rootView; 27 | private Fragment mFragment; 28 | private OnSortItemClickListener onSortItemClickListener; 29 | 30 | public SortMenuPopupWindow(Fragment fragment) { 31 | mFragment = fragment; 32 | LayoutInflater inflater = LayoutInflater.from(fragment.getContext()); 33 | rootView = inflater.inflate(R.layout.sort_popup_window_menu, null); 34 | setContentView(rootView); 35 | ButterKnife.bind(this, rootView); 36 | //设置高度和宽度。 37 | this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 38 | this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); 39 | this.setFocusable(true); 40 | 41 | //设置动画效果 42 | this.setAnimationStyle(R.style.PopupWindowAnimStyle); 43 | 44 | //当单击Back键或者其他地方使其消失、需要设置这个属性。 45 | rootView.setOnKeyListener(this); 46 | rootView.setFocusable(true); 47 | rootView.setFocusableInTouchMode(true); 48 | //实例化一个ColorDrawable颜色为半透明 49 | ColorDrawable dw = new ColorDrawable(Color.TRANSPARENT); 50 | //设置SelectPicPopupWindow弹出窗体的背景 51 | this.setBackgroundDrawable(dw); 52 | this.setOutsideTouchable(true); 53 | } 54 | 55 | //点back键消失 56 | @Override 57 | public boolean onKey(View v, int keyCode, KeyEvent event) { 58 | if (keyCode == KeyEvent.KEYCODE_BACK && this.isShowing()) { 59 | this.dismiss(); 60 | return true; 61 | } 62 | return false; 63 | } 64 | 65 | public void setOnSortItemClickListener(OnSortItemClickListener listener) { 66 | this.onSortItemClickListener = listener; 67 | } 68 | 69 | @OnClick({R.id.id_close_sort_menu, R.id.id_sort_name, R.id.id_sort_desc, R.id.id_sort_asc, R.id.id_sort_midify_date}) 70 | public void onClick(View view) { 71 | String path = ""; 72 | if (mFragment.getView() != null){ 73 | TextView pathTv = mFragment.getView().findViewById(R.id.id_now_file_path_tv); 74 | path = pathTv.getText().toString(); 75 | } 76 | switch (view.getId()) { 77 | case R.id.id_close_sort_menu: 78 | onSortItemClickListener.closeMenu(); 79 | break; 80 | case R.id.id_sort_name: 81 | onSortItemClickListener.sortByName(path); 82 | break; 83 | case R.id.id_sort_desc: 84 | onSortItemClickListener.sortBySizeDesc(path); 85 | break; 86 | case R.id.id_sort_asc: 87 | onSortItemClickListener.sortBySizeAsc(path); 88 | break; 89 | case R.id.id_sort_midify_date: 90 | onSortItemClickListener.sortByModifyDate(path); 91 | break; 92 | default: 93 | } 94 | } 95 | 96 | 97 | public interface OnSortItemClickListener { 98 | void closeMenu(); 99 | void sortByName(String path); 100 | void sortBySizeDesc(String path); 101 | void sortBySizeAsc(String path); 102 | void sortByModifyDate(String path); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/res/anim/top_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/top_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-mdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_apk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_apk.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_bluetooth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_bluetooth.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_cloud_disk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_cloud_disk.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_default.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_document.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_download.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_favorites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_favorites.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_file.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_folder.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_music.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_music.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_picture.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_popular_expression.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_popular_expression.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_remote_manage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_remote_manage.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_video.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xhdpi/ic_zip.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/drawable-xxhdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_add_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_drop_down_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close_24dp.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_content_copy_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_content_paste_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_divider_line_gray.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_format_list_numbered_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_more_vert_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_next_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/radius_rect_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 12 | 22 | 32 | 33 | 37 | 42 | 46 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/category_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 14 | 22 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/common_app_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/file_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 25 | 36 | 47 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_file_category.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | 14 | 18 | 32 | 33 | 45 | 46 | 50 | 56 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_file_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 | 15 | 19 | 33 | 34 | 35 | 39 | 51 | 52 | 58 | 59 | 63 | 69 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /app/src/main/res/layout/input_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 15 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 17 | 18 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/operation_popup_window_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 24 | 25 | 34 | 41 | 48 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /app/src/main/res/layout/sort_popup_window_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 24 | 25 | 34 | 41 | 48 | 55 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/res/menu/file_list_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/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 | #FEFEFE 4 | #EEEEEF 5 | #64BCFA 6 | #EEEEF0 7 | #64BCFA 8 | #FFFFFF 9 | #BFBFBF 10 | #b0000000 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FileExplorer 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 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 16 | 17 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/test/java/com/codekong/fileexplorer/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.codekong.fileexplorer; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * Example local unit test, which will execute on the development machine (host). 7 | * 8 | * @see Testing documentation 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /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{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} 7 | google() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.0.1' 11 | classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1' 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | //jcenter() 20 | maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'} 21 | google() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Dec 12 20:33:54 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/img/1.png -------------------------------------------------------------------------------- /img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linkecoding/FileExplorer/06360083b3937c8f09b991e321221d0f192346d1/img/2.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------