├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── aghajari │ │ └── app │ │ └── androidr │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── aghajari │ │ │ └── app │ │ │ └── androidr │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ ├── Adapter.java │ │ │ ├── AndroidFolderInterface.java │ │ │ ├── CacheManager.java │ │ │ ├── FileInterface.java │ │ │ └── OpenFolderTask.java │ │ │ └── utils │ │ │ ├── DividerItemDecoration.java │ │ │ ├── EmptyItemDecoration.java │ │ │ ├── FileUtil.java │ │ │ └── PermissionUtils.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── file.png │ │ ├── folder.png │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── rv_item_dir.xml │ │ └── rv_item_file.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── aghajari │ └── app │ └── androidr │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── Screen1.jpg └── Screen2.jpg └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidDirectoryAccess 2 | 3 | 4 | Simple project to get Android/{data,obb} directory access for Android >= 11 without root. (Supports all versions of Android) 5 | 6 | - [x] Doesn't need root. 7 | - [x] Useful for File Managers on Android >= 11. 8 | - [x] Tested on Android 11 & 10 & 7. 9 | - [x] Android/data directory access 10 | - [x] Android/obb directory access 11 | 12 | ## Author 13 | - **Amir Hossein Aghajari** 14 | 15 | License 16 | ======= 17 | 18 | Copyright 2021 Amir Hossein Aghajari 19 | Licensed under the Apache License, Version 2.0 (the "License"); 20 | you may not use this file except in compliance with the License. 21 | You may obtain a copy of the License at 22 | 23 | http://www.apache.org/licenses/LICENSE-2.0 24 | 25 | Unless required by applicable law or agreed to in writing, software 26 | distributed under the License is distributed on an "AS IS" BASIS, 27 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 | See the License for the specific language governing permissions and 29 | limitations under the License. 30 | 31 | 32 |

33 |
34 | LCoders | AmirHosseinAghajari 35 |
Amir Hossein AghajariEmailGitHub 36 |
37 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | compileSdkVersion 30 7 | 8 | defaultConfig { 9 | applicationId "com.aghajari.app.androidr" 10 | minSdkVersion 19 11 | targetSdkVersion 30 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation 'com.github.bumptech.glide:glide:4.12.0' 32 | 33 | implementation 'androidx.appcompat:appcompat:1.2.0' 34 | implementation 'com.google.android.material:material:1.3.0' 35 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 36 | testImplementation 'junit:junit:4.+' 37 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 39 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/aghajari/app/androidr/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("com.aghajari.app.androidr", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr; 2 | 3 | import androidx.annotation.Nullable; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.os.Handler; 10 | 11 | import com.aghajari.app.androidr.adapter.Adapter; 12 | import com.aghajari.app.androidr.utils.DividerItemDecoration; 13 | import com.aghajari.app.androidr.utils.EmptyItemDecoration; 14 | import com.aghajari.app.androidr.utils.PermissionUtils; 15 | 16 | import java.io.File; 17 | 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | public final static int REQUEST_CODE = 100; 21 | 22 | Adapter adapter; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_main); 28 | 29 | adapter = new Adapter(this, findViewById(R.id.loading_parent)); 30 | 31 | RecyclerView rv = findViewById(R.id.rv); 32 | rv.setAdapter(adapter); 33 | rv.addItemDecoration(new DividerItemDecoration(this, 34 | DividerItemDecoration.VERTICAL, 35 | new int[]{dp(84), dp(24)})); 36 | rv.addItemDecoration(new EmptyItemDecoration(dp(20))); 37 | 38 | if (PermissionUtils.checkAndRequestPermissions(this, REQUEST_CODE, 2)) 39 | load(); 40 | } 41 | 42 | @Override 43 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 44 | super.onActivityResult(requestCode, resultCode, data); 45 | 46 | if (requestCode == REQUEST_CODE && data != null && data.getData() != null) { 47 | PermissionUtils.grantUriPermission(this, data.getData()); 48 | load(); 49 | } 50 | PermissionUtils.checkAndRequestPermissions(this, REQUEST_CODE, 2); 51 | } 52 | 53 | @Override 54 | public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 55 | super.onRequestPermissionsResult(requestCode,permissions,grantResults); 56 | 57 | if (PermissionUtils.checkAndRequestPermissions(this, REQUEST_CODE, 2)) 58 | load(); 59 | } 60 | 61 | private void load() { 62 | adapter.load(PermissionUtils.getAndroidFolderUri(PermissionUtils.ANDROID, true)); 63 | } 64 | 65 | @Override 66 | public void onBackPressed() { 67 | if (!adapter.backFolder()) 68 | super.onBackPressed(); 69 | } 70 | 71 | private int dp(int value) { 72 | return (int) (getResources().getDisplayMetrics().density * value); 73 | } 74 | } -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/adapter/Adapter.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.adapter; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.net.Uri; 6 | import android.os.Parcelable; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.LinearLayout; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import androidx.annotation.NonNull; 15 | import androidx.appcompat.widget.AppCompatImageView; 16 | import androidx.documentfile.provider.DocumentFile; 17 | import androidx.recyclerview.widget.RecyclerView; 18 | 19 | import com.aghajari.app.androidr.utils.FileUtil; 20 | import com.aghajari.app.androidr.MainActivity; 21 | import com.aghajari.app.androidr.utils.PermissionUtils; 22 | import com.aghajari.app.androidr.R; 23 | import com.bumptech.glide.Glide; 24 | 25 | import java.io.File; 26 | import java.text.SimpleDateFormat; 27 | import java.util.ArrayList; 28 | import java.util.Date; 29 | import java.util.List; 30 | 31 | public class Adapter extends RecyclerView.Adapter { 32 | 33 | public static boolean SHOW_HIDDEN_FILES = true; 34 | 35 | private final SimpleDateFormat format = new SimpleDateFormat("dd MMM hh:mm a"); 36 | final Context context; 37 | private RecyclerView.LayoutManager layoutManager = null; 38 | 39 | private FileInterface parentDir = null; 40 | private FileInterface selectedDir = null; 41 | final List> list = new ArrayList<>(); 42 | 43 | //loading 44 | final LinearLayout loading; 45 | final TextView loading_progress; 46 | 47 | private OpenFolderTask task = null; 48 | 49 | public Adapter(Context context, LinearLayout loading) { 50 | this.context = context; 51 | this.loading = loading; 52 | loading_progress = loading.findViewById(R.id.loading_progress); 53 | } 54 | 55 | public boolean isEmpty() { 56 | return getItemCount() == 0 && loading.getVisibility() == View.GONE; 57 | } 58 | 59 | public void load(Uri treeUri) { 60 | if (PermissionUtils.needToUseDocumentFile()) { 61 | parentDir = AndroidFolderInterface.fromDocumentFile(DocumentFile.fromTreeUri(context, treeUri)); 62 | } else { 63 | parentDir = AndroidFolderInterface.fromFile(new File(FileUtil.getFullPathFromTreeUri(treeUri, context))); 64 | } 65 | openFolder(parentDir, false); 66 | } 67 | 68 | public void load(File file) { 69 | parentDir = FileInterface.fromFile(file); 70 | openFolder(parentDir, false); 71 | } 72 | 73 | public void openFolder(FileInterface file, boolean save) { 74 | if (task != null) 75 | task.cancel(true); 76 | 77 | if (save && selectedDir != null) 78 | CacheManager.saveState(selectedDir.getUri(), layoutManager.onSaveInstanceState()); 79 | 80 | selectedDir = file; 81 | list.clear(); 82 | notifyDataSetChanged(); 83 | loading.setVisibility(View.INVISIBLE); 84 | 85 | task = new OpenFolderTask(this); 86 | task.execute(file); 87 | } 88 | 89 | public boolean backFolder() { 90 | if (selectedDir != null) 91 | CacheManager.removeState(selectedDir.getUri()); 92 | 93 | if (task != null) 94 | task.cancel(true); 95 | 96 | if (parentDir == null || selectedDir.equals(parentDir)) 97 | return false; 98 | 99 | FileInterface select = selectedDir.getParentFile(); 100 | if (select == null || 101 | select.getAbsolutePath(context).equalsIgnoreCase(parentDir.getAbsolutePath(context))) 102 | openFolder(parentDir, false); 103 | else 104 | openFolder(select, false); 105 | return true; 106 | } 107 | 108 | void loaded() { 109 | Parcelable state = CacheManager.getState(selectedDir.getUri()); 110 | if (state != null) 111 | layoutManager.onRestoreInstanceState(state); 112 | } 113 | 114 | @NonNull 115 | @Override 116 | public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 117 | if (viewType == 0) { 118 | return new VH(LayoutInflater.from(parent.getContext()) 119 | .inflate(R.layout.rv_item_dir, parent, false)); 120 | } else { 121 | return new VH(LayoutInflater.from(parent.getContext()) 122 | .inflate(R.layout.rv_item_file, parent, false)); 123 | } 124 | } 125 | 126 | @Override 127 | public void onBindViewHolder(@NonNull VH holder, int position) { 128 | holder.bind(list.get(position)); 129 | } 130 | 131 | @Override 132 | public int getItemCount() { 133 | return list.size(); 134 | } 135 | 136 | @Override 137 | public int getItemViewType(int position) { 138 | return list.get(position).isDirectory() ? 0 : 1; 139 | } 140 | 141 | @Override 142 | public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { 143 | super.onAttachedToRecyclerView(recyclerView); 144 | this.layoutManager = recyclerView.getLayoutManager(); 145 | } 146 | 147 | public class VH extends RecyclerView.ViewHolder { 148 | 149 | AppCompatImageView img; 150 | TextView name, date, count; 151 | 152 | public VH(@NonNull View itemView) { 153 | super(itemView); 154 | 155 | name = itemView.findViewById(R.id.name); 156 | date = itemView.findViewById(R.id.date); 157 | count = itemView.findViewById(R.id.count); 158 | 159 | img = itemView.findViewById(R.id.img); 160 | } 161 | 162 | public void bind(final FileInterface file) { 163 | if (file == null) return; 164 | 165 | // hidden file 166 | if (file.getName().startsWith(".")) 167 | img.setAlpha(0.4f); 168 | else 169 | img.setAlpha(1f); 170 | 171 | name.setText(file.getName()); 172 | date.setText(format.format(new Date(file.lastModified()))); 173 | 174 | if (file.isDirectory()) { 175 | Glide.with(img).load(R.drawable.folder).into(img); 176 | 177 | if (PermissionUtils.needToGetPermission(context, file)) 178 | count.setText("Permission Needed! (Click)"); 179 | else 180 | count.setText(file.getListFilesCount() + " items"); 181 | 182 | itemView.setOnClickListener(new View.OnClickListener() { 183 | @Override 184 | public void onClick(View view) { 185 | if (PermissionUtils.needToGetPermission(context, file)) { 186 | PermissionUtils.requestAndroidFolderPermission((Activity) context, MainActivity.REQUEST_CODE, file); 187 | } else if (file.exists()) { 188 | openFolder(file, true); 189 | } 190 | } 191 | }); 192 | } else { 193 | Glide.with(img).load(R.drawable.file).into(img); 194 | itemView.setOnClickListener(new View.OnClickListener() { 195 | @Override 196 | public void onClick(View view) { 197 | String text = "Path : " + file.getAbsolutePath(context) 198 | + "\nSize : " + FileUtil.humanReadableByteCountSI(file.length()); 199 | Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); 200 | } 201 | }); 202 | } 203 | 204 | itemView.setOnLongClickListener(new View.OnLongClickListener() { 205 | @Override 206 | public boolean onLongClick(View view) { 207 | String text = file.getAbsolutePath(context); 208 | Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); 209 | return true; 210 | } 211 | }); 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/adapter/AndroidFolderInterface.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.adapter; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.documentfile.provider.DocumentFile; 7 | 8 | import com.aghajari.app.androidr.utils.PermissionUtils; 9 | 10 | import java.io.File; 11 | import java.util.List; 12 | 13 | /** 14 | * a FileInterface for root of Android folder. 15 | * Will force to add Android/data and Android/obb folders on Android 11 (R) or newer. 16 | */ 17 | public class AndroidFolderInterface extends FileInterface { 18 | 19 | AndroidFolderInterface(@NonNull T file) { 20 | super(file); 21 | } 22 | 23 | public static AndroidFolderInterface fromDocumentFile(@NonNull DocumentFile documentFile) { 24 | return new AndroidFolderInterface<>(documentFile); 25 | } 26 | 27 | public static AndroidFolderInterface fromFile(@NonNull File file) { 28 | return new AndroidFolderInterface<>(file); 29 | } 30 | 31 | public static AndroidFolderInterface fromFileInterface(@NonNull FileInterface file) { 32 | if (file instanceof AndroidFolderInterface) return (AndroidFolderInterface) file; 33 | return new AndroidFolderInterface<>(file.file); 34 | } 35 | 36 | @Override 37 | protected List> internalListFiles(Context context) { 38 | List> list = super.internalListFiles(context); 39 | checkDataAndObb(context, list); 40 | return list; 41 | } 42 | 43 | public void checkDataAndObb(Context context, List> list) { 44 | if (PermissionUtils.needToUseDocumentFile()) { 45 | boolean obb = false, data = false; 46 | for (FileInterface f : list) { 47 | if (f.getName().equalsIgnoreCase("obb")) 48 | obb = true; 49 | if (f.getName().equalsIgnoreCase("data")) 50 | data = true; 51 | 52 | if (obb && data) break; 53 | } 54 | 55 | if (!obb) 56 | checkDir(context, PermissionUtils.ANDROID_OBB, "obb", list); 57 | if (!data) 58 | checkDir(context, PermissionUtils.ANDROID_DATA, "data", list); 59 | } 60 | } 61 | 62 | private void checkDir(Context context, String id, String name, List> list) { 63 | File file = new File(getAbsolutePath(context), name) { 64 | @Override 65 | public boolean isDirectory() { 66 | return true; 67 | } 68 | 69 | @Override 70 | public boolean exists() { 71 | return false; 72 | } 73 | }; 74 | 75 | if (PermissionUtils.needToGetPermission(context, file)) { 76 | list.add(0, FileInterface.fromFile(file)); 77 | } else { 78 | list.add(0, FileInterface.fromDocumentFile(DocumentFile.fromTreeUri(context, PermissionUtils.getAndroidFolderUri(id, true)))); 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/adapter/CacheManager.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.adapter; 2 | 3 | import android.net.Uri; 4 | import android.os.Parcelable; 5 | 6 | import java.util.List; 7 | import java.util.WeakHashMap; 8 | 9 | /** 10 | * 1. Cache loaded folder files 11 | * for a better performance on second load. 12 | *

13 | * 2. Cache RecyclerView's LayoutManager state 14 | * for showing the previous position when {@link Adapter#backFolder()} called. 15 | */ 16 | final class CacheManager { 17 | 18 | private static final WeakHashMap>> cached = new WeakHashMap<>(); 19 | 20 | public static List> get(Uri uri) { 21 | return cached.get(uri); 22 | } 23 | 24 | public static void put(Uri uri, List> files) { 25 | cached.put(uri, files); 26 | } 27 | 28 | public static List> remove(Uri uri) { 29 | return cached.remove(uri); 30 | } 31 | 32 | public static boolean contains(Uri uri) { 33 | return cached.containsKey(uri); 34 | } 35 | 36 | // **** 37 | 38 | private static final WeakHashMap cachedStates = new WeakHashMap<>(); 39 | 40 | public static Parcelable getState(Uri uri) { 41 | return cachedStates.get(uri); 42 | } 43 | 44 | public static void saveState(Uri uri, Parcelable state) { 45 | cachedStates.put(uri, state); 46 | } 47 | 48 | public static Parcelable removeState(Uri uri) { 49 | return cachedStates.remove(uri); 50 | } 51 | 52 | public static boolean containsState(Uri uri) { 53 | return cachedStates.containsKey(uri); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/adapter/FileInterface.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.adapter; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | 6 | import androidx.annotation.NonNull; 7 | import androidx.documentfile.provider.DocumentFile; 8 | 9 | import com.aghajari.app.androidr.utils.FileUtil; 10 | 11 | import java.io.File; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * a File interface to read File/DocumentFile easier. 17 | * Use DocumentFile on Android 11 (R) or newer. 18 | * Use File (normal) for older versions of android. 19 | */ 20 | public class FileInterface { 21 | @NonNull 22 | protected final T file; 23 | 24 | private boolean isDirectory; 25 | private String cachedName; 26 | private long cachedLastModify; 27 | private int cacheListFilesCount = -1; 28 | private Uri cachedUri = null; 29 | 30 | FileInterface(@NonNull T file) { 31 | this.file = file; 32 | 33 | internalIsDirectory(); // do not comment this one 34 | // cache data 35 | internalName(); 36 | getListFilesCount(); 37 | lastModified(); 38 | } 39 | 40 | public static FileInterface fromDocumentFile(@NonNull DocumentFile documentFile) { 41 | return new FileInterface<>(documentFile); 42 | } 43 | 44 | public static FileInterface fromFile(@NonNull File file) { 45 | return new FileInterface<>(file); 46 | } 47 | 48 | DocumentFile asDocumentFile() { 49 | return (DocumentFile) file; 50 | } 51 | 52 | File asFile() { 53 | return (File) file; 54 | } 55 | 56 | public boolean canRead() { 57 | if (file instanceof DocumentFile) 58 | return asDocumentFile().canRead(); 59 | else 60 | return asFile().canRead(); 61 | } 62 | 63 | public boolean canWrite() { 64 | if (file instanceof DocumentFile) 65 | return asDocumentFile().canWrite(); 66 | else 67 | return asFile().canWrite(); 68 | } 69 | 70 | public boolean isFile() { 71 | if (file instanceof DocumentFile) 72 | return asDocumentFile().isFile(); 73 | else 74 | return asFile().isFile(); 75 | } 76 | 77 | protected void internalUri() { 78 | if (cachedUri == null) 79 | return; 80 | Uri uri; 81 | if (file instanceof DocumentFile) 82 | uri = asDocumentFile().getUri(); 83 | else 84 | uri = Uri.fromFile(asFile()); 85 | if (!uri.equals(cachedUri)) { 86 | if (CacheManager.contains(cachedUri)) { 87 | CacheManager.put(uri, CacheManager.remove(cachedUri)); 88 | } 89 | if (CacheManager.containsState(cachedUri)) { 90 | CacheManager.saveState(uri, CacheManager.removeState(cachedUri)); 91 | } 92 | } 93 | cachedUri = uri; 94 | } 95 | 96 | public Uri getUri() { 97 | if (cachedUri != null) 98 | return cachedUri; 99 | 100 | if (file instanceof DocumentFile) 101 | return cachedUri = asDocumentFile().getUri(); 102 | else 103 | return cachedUri = Uri.fromFile(asFile()); 104 | } 105 | 106 | public boolean delete() { 107 | if (file instanceof DocumentFile) 108 | return asDocumentFile().delete(); 109 | else 110 | return asFile().delete(); 111 | } 112 | 113 | public boolean renameTo(String displayName) { 114 | boolean res; 115 | if (file instanceof DocumentFile) 116 | res = asDocumentFile().renameTo(displayName); 117 | else 118 | res = asFile().renameTo(new File(asFile().getParent(), displayName)); 119 | cachedName = internalName(); 120 | cachedLastModify = lastModified(); 121 | internalUri(); //update caches 122 | return res; 123 | } 124 | 125 | protected void internalIsDirectory() { 126 | if (file instanceof DocumentFile) { 127 | isDirectory = asDocumentFile().isDirectory(); 128 | } else { 129 | isDirectory = asFile().isDirectory(); 130 | } 131 | } 132 | 133 | public boolean isDirectory() { 134 | return isDirectory; 135 | } 136 | 137 | public String getAbsolutePath(Context context) { 138 | if (file instanceof DocumentFile) 139 | return FileUtil.getPath(context, asDocumentFile().getUri()); 140 | else 141 | return asFile().getAbsolutePath(); 142 | } 143 | 144 | public boolean exists() { 145 | if (file instanceof DocumentFile) 146 | return asDocumentFile().exists(); 147 | else 148 | return asFile().exists(); 149 | } 150 | 151 | protected String internalName() { 152 | if (file instanceof DocumentFile) 153 | return cachedName = asDocumentFile().getName(); 154 | else 155 | return cachedName = asFile().getName(); 156 | } 157 | 158 | public String getName() { 159 | if (cachedName == null) 160 | return internalName(); 161 | return cachedName; 162 | } 163 | 164 | public long length() { 165 | if (file instanceof DocumentFile) 166 | return asDocumentFile().length(); 167 | else 168 | return asFile().length(); 169 | } 170 | 171 | public long lastModified() { 172 | if (cachedLastModify >= 0) 173 | return cachedLastModify; 174 | 175 | if (file instanceof DocumentFile) 176 | return cachedLastModify = asDocumentFile().lastModified(); 177 | else 178 | return cachedLastModify = asFile().lastModified(); 179 | } 180 | 181 | protected List> internalListFiles(Context context) { 182 | Uri uri = getUri(); 183 | if (CacheManager.get(uri) != null) { 184 | return CacheManager.get(uri); 185 | } 186 | 187 | List> list = new ArrayList<>(); 188 | if (file instanceof DocumentFile) { 189 | if (asDocumentFile().listFiles() == null) 190 | return null; 191 | 192 | for (DocumentFile f : asDocumentFile().listFiles()) { 193 | if (!Adapter.SHOW_HIDDEN_FILES && f.getName().startsWith(".")) 194 | continue; 195 | list.add(FileInterface.fromDocumentFile(f)); 196 | } 197 | } else { 198 | if (asFile().listFiles() == null) 199 | return null; 200 | 201 | for (File f : asFile().listFiles()) { 202 | if (!Adapter.SHOW_HIDDEN_FILES && f.getName().startsWith(".")) 203 | continue; 204 | list.add(FileInterface.fromFile(f)); 205 | } 206 | } 207 | CacheManager.put(uri, list); 208 | return list; 209 | } 210 | 211 | public FileInterface[] listFiles(Context context) { 212 | return internalListFiles(context).toArray(new FileInterface[0]); 213 | } 214 | 215 | public int getListFilesCount() { 216 | if (cacheListFilesCount >= 0) 217 | return cacheListFilesCount; 218 | 219 | if (file instanceof DocumentFile) { 220 | if (asDocumentFile().listFiles() == null) 221 | return cacheListFilesCount = 0; 222 | 223 | if (Adapter.SHOW_HIDDEN_FILES) { 224 | return cacheListFilesCount = asDocumentFile().listFiles().length; 225 | } else { 226 | cacheListFilesCount = 0; 227 | for (DocumentFile f : asDocumentFile().listFiles()) { 228 | if (!Adapter.SHOW_HIDDEN_FILES && f.getName().startsWith(".")) continue; 229 | cacheListFilesCount++; 230 | } 231 | return cacheListFilesCount; 232 | } 233 | } else { 234 | if (asFile().listFiles() == null) 235 | return cacheListFilesCount = 0; 236 | 237 | if (Adapter.SHOW_HIDDEN_FILES) { 238 | return cacheListFilesCount = asFile().listFiles().length; 239 | } else { 240 | cacheListFilesCount = 0; 241 | for (File f : asFile().listFiles()) { 242 | if (!Adapter.SHOW_HIDDEN_FILES && f.getName().startsWith(".")) continue; 243 | cacheListFilesCount++; 244 | } 245 | return cacheListFilesCount; 246 | } 247 | } 248 | } 249 | 250 | public FileInterface getParentFile() { 251 | if (file instanceof DocumentFile) { 252 | if (asDocumentFile().getParentFile() == null) return null; 253 | return FileInterface.fromDocumentFile(asDocumentFile().getParentFile()); 254 | } else { 255 | if (asFile().getParentFile() == null) return null; 256 | return FileInterface.fromFile(asFile().getParentFile()); 257 | } 258 | } 259 | 260 | @Override 261 | public boolean equals(Object o) { 262 | if (this == o) return true; 263 | if (o == null || getClass() != o.getClass()) return false; 264 | 265 | FileInterface that = (FileInterface) o; 266 | return file.equals(that.file); 267 | } 268 | 269 | @Override 270 | public int hashCode() { 271 | return file.hashCode(); 272 | } 273 | } 274 | -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/adapter/OpenFolderTask.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.adapter; 2 | 3 | import android.net.Uri; 4 | import android.os.AsyncTask; 5 | import android.os.Handler; 6 | import android.view.View; 7 | 8 | import androidx.documentfile.provider.DocumentFile; 9 | 10 | import java.io.File; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Task to load a folder files with progress. 16 | */ 17 | final class OpenFolderTask extends AsyncTask, Integer, List>> { 18 | final Adapter adapter; 19 | boolean loading = true; 20 | 21 | OpenFolderTask(Adapter adapter) { 22 | super(); 23 | this.adapter = adapter; 24 | } 25 | 26 | @Override 27 | protected List> doInBackground(FileInterface... file) { 28 | Uri uri = file[0].getUri(); 29 | if (CacheManager.get(uri) != null) { 30 | return CacheManager.get(uri); 31 | } 32 | 33 | List> list = new ArrayList<>(); 34 | int max; 35 | 36 | if (file[0].file instanceof DocumentFile) { 37 | if (file[0].asDocumentFile().listFiles() == null) 38 | return null; 39 | 40 | DocumentFile[] files = file[0].asDocumentFile().listFiles(); 41 | max = files.length; 42 | for (int i = 1; i <= max; i++) { 43 | if (isCancelled()) 44 | return null; 45 | if (!Adapter.SHOW_HIDDEN_FILES && files[i - 1].getName().startsWith(".")) 46 | continue; 47 | 48 | publishProgress(i, max); 49 | list.add(FileInterface.fromDocumentFile(files[i - 1])); 50 | } 51 | } else { 52 | if (file[0].asFile().listFiles() == null) 53 | return null; 54 | 55 | File[] files = file[0].asFile().listFiles(); 56 | max = files.length; 57 | for (int i = 1; i <= max; i++) { 58 | if (isCancelled()) 59 | return null; 60 | if (!Adapter.SHOW_HIDDEN_FILES && files[i - 1].getName().startsWith(".")) 61 | continue; 62 | 63 | publishProgress(i, max); 64 | list.add(FileInterface.fromFile(files[i - 1])); 65 | } 66 | } 67 | CacheManager.put(uri, list); 68 | 69 | if (file[0] instanceof AndroidFolderInterface) { 70 | ((AndroidFolderInterface) file[0]).checkDataAndObb(adapter.context, list); 71 | } 72 | return list; 73 | } 74 | 75 | private final static Handler handler = new Handler(); 76 | 77 | @Override 78 | protected void onPreExecute() { 79 | super.onPreExecute(); 80 | handler.postDelayed(new Runnable() { 81 | @Override 82 | public void run() { 83 | if (loading) 84 | adapter.loading.setVisibility(View.VISIBLE); 85 | } 86 | }, 100); 87 | } 88 | 89 | @Override 90 | protected void onPostExecute(List> files) { 91 | super.onPostExecute(files); 92 | loading = false; 93 | if (!isCancelled() && files != null) { 94 | adapter.list.addAll(files); 95 | adapter.loading.setVisibility(View.GONE); 96 | adapter.notifyDataSetChanged(); 97 | adapter.loaded(); 98 | } 99 | } 100 | 101 | @Override 102 | protected void onProgressUpdate(Integer... values) { 103 | super.onProgressUpdate(values); 104 | if (!isCancelled()) { 105 | adapter.loading_progress.setText(values[0] + "/" + values[1]); 106 | } 107 | } 108 | 109 | @Override 110 | protected void onCancelled() { 111 | super.onCancelled(); 112 | loading = false; 113 | adapter.loading.setVisibility(View.GONE); 114 | adapter.notifyDataSetChanged(); 115 | } 116 | } -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/utils/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.utils; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | import android.graphics.drawable.Drawable; 8 | import android.view.View; 9 | import android.widget.LinearLayout; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.core.view.ViewCompat; 13 | import androidx.recyclerview.widget.RecyclerView; 14 | 15 | /** 16 | * DividerItemDecoration is a {@link RecyclerView.ItemDecoration} that can be used as a divider 17 | * between items of a {@link androidx.recyclerview.widget.LinearLayoutManager}. It supports both {@link #HORIZONTAL} and 18 | * {@link #VERTICAL} orientations. 19 | * 20 | *

 21 |  *     mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
 22 |  *             mLayoutManager.getOrientation());
 23 |  *     recyclerView.addItemDecoration(mDividerItemDecoration);
 24 |  * 
25 | */ 26 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 27 | public static final int HORIZONTAL = LinearLayout.HORIZONTAL; 28 | public static final int VERTICAL = LinearLayout.VERTICAL; 29 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; 30 | private Drawable mDivider; 31 | 32 | private final int[] padding; 33 | 34 | /** 35 | * Current orientation. Either {@link #HORIZONTAL} or {@link #VERTICAL}. 36 | */ 37 | private int mOrientation; 38 | private final Rect mBounds = new Rect(); 39 | 40 | /** 41 | * Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a 42 | * {@link androidx.recyclerview.widget.LinearLayoutManager}. 43 | * 44 | * @param context Current context, it will be used to access resources. 45 | * @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}. 46 | */ 47 | public DividerItemDecoration(Context context, int orientation, int[] padding) { 48 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 49 | mDivider = a.getDrawable(0); 50 | a.recycle(); 51 | setOrientation(orientation); 52 | this.padding = padding; 53 | } 54 | 55 | /** 56 | * Sets the orientation for this divider. This should be called if 57 | * {@link RecyclerView.LayoutManager} changes orientation. 58 | * 59 | * @param orientation {@link #HORIZONTAL} or {@link #VERTICAL} 60 | */ 61 | public void setOrientation(int orientation) { 62 | if (orientation != HORIZONTAL && orientation != VERTICAL) { 63 | throw new IllegalArgumentException( 64 | "Invalid orientation. It should be either HORIZONTAL or VERTICAL"); 65 | } 66 | mOrientation = orientation; 67 | } 68 | 69 | /** 70 | * Sets the {@link Drawable} for this divider. 71 | * 72 | * @param drawable Drawable that should be used as a divider. 73 | */ 74 | public void setDrawable(@NonNull Drawable drawable) { 75 | if (drawable == null) { 76 | throw new IllegalArgumentException("Drawable cannot be null."); 77 | } 78 | mDivider = drawable; 79 | } 80 | 81 | @Override 82 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 83 | if (parent.getLayoutManager() == null) { 84 | return; 85 | } 86 | if (mOrientation == VERTICAL) { 87 | drawVertical(c, parent); 88 | } else { 89 | drawHorizontal(c, parent); 90 | } 91 | } 92 | 93 | private void drawVertical(Canvas canvas, RecyclerView parent) { 94 | canvas.save(); 95 | final int left; 96 | final int right; 97 | if (parent.getClipToPadding()) { 98 | left = parent.getPaddingLeft() + padding[0]; 99 | right = parent.getWidth() - parent.getPaddingRight() - padding[1]; 100 | canvas.clipRect(left, parent.getPaddingTop(), right, 101 | parent.getHeight() - parent.getPaddingBottom()); 102 | } else { 103 | left = padding[0]; 104 | right = parent.getWidth() - padding[1]; 105 | } 106 | final int childCount = parent.getChildCount(); 107 | for (int i = 0; i < childCount; i++) { 108 | final View child = parent.getChildAt(i); 109 | 110 | //skip last item 111 | if (parent.getChildViewHolder(child).getAdapterPosition() == parent.getAdapter().getItemCount() - 1) 112 | continue; 113 | 114 | parent.getDecoratedBoundsWithMargins(child, mBounds); 115 | final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child)); 116 | final int top = bottom - mDivider.getIntrinsicHeight(); 117 | mDivider.setBounds(left, top, right, bottom); 118 | mDivider.draw(canvas); 119 | } 120 | canvas.restore(); 121 | } 122 | 123 | private void drawHorizontal(Canvas canvas, RecyclerView parent) { 124 | canvas.save(); 125 | final int top; 126 | final int bottom; 127 | if (parent.getClipToPadding()) { 128 | top = parent.getPaddingTop() + padding[0]; 129 | bottom = parent.getHeight() - parent.getPaddingBottom() - padding[1]; 130 | canvas.clipRect(parent.getPaddingLeft(), top, 131 | parent.getWidth() - parent.getPaddingRight(), bottom); 132 | } else { 133 | top = padding[0]; 134 | bottom = parent.getHeight() - padding[1]; 135 | } 136 | final int childCount = parent.getChildCount(); 137 | for (int i = 0; i < childCount; i++) { 138 | final View child = parent.getChildAt(i); 139 | 140 | //skip last item 141 | if (parent.getChildViewHolder(child).getAdapterPosition() == parent.getAdapter().getItemCount() - 1) 142 | continue; 143 | 144 | parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds); 145 | final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child)); 146 | final int left = right - mDivider.getIntrinsicWidth(); 147 | mDivider.setBounds(left, top, right, bottom); 148 | mDivider.draw(canvas); 149 | } 150 | canvas.restore(); 151 | } 152 | 153 | @Override 154 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 155 | RecyclerView.State state) { 156 | if (mOrientation == VERTICAL) { 157 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 158 | } else { 159 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/utils/EmptyItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.utils; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Canvas; 5 | import android.graphics.Paint; 6 | import android.graphics.Rect; 7 | 8 | import androidx.recyclerview.widget.RecyclerView; 9 | 10 | import com.aghajari.app.androidr.adapter.Adapter; 11 | 12 | public class EmptyItemDecoration extends RecyclerView.ItemDecoration { 13 | Paint paint; 14 | 15 | public EmptyItemDecoration(int size) { 16 | paint = new Paint(); 17 | //paint.setColor(Color.LTGRAY); 18 | //paint.setTypeface(Typeface.DEFAULT_BOLD); 19 | paint.setTextSize(size); 20 | } 21 | 22 | @Override 23 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 24 | if (parent.getLayoutManager() == null) 25 | return; 26 | 27 | if (parent.getAdapter().getItemCount() == 0 28 | && !PermissionUtils.hasAllPermissions((Activity) parent.getContext())) 29 | drawCenter(c,paint,"Permissions Needed!"); 30 | 31 | else if (((Adapter) parent.getAdapter()).isEmpty()) 32 | drawCenter(c, paint, "No files"); 33 | } 34 | 35 | private final Rect r = new Rect(); 36 | 37 | private void drawCenter(Canvas canvas, Paint paint, String text) { 38 | canvas.getClipBounds(r); 39 | int cHeight = r.height(); 40 | int cWidth = r.width(); 41 | paint.setTextAlign(Paint.Align.LEFT); 42 | paint.getTextBounds(text, 0, text.length(), r); 43 | float x = cWidth / 2f - r.width() / 2f - r.left; 44 | float y = cHeight / 2f + r.height() / 2f - r.bottom; 45 | canvas.drawText(text, x, y, paint); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/utils/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.annotation.TargetApi; 5 | import android.content.ContentUris; 6 | import android.content.Context; 7 | import android.database.Cursor; 8 | import android.net.Uri; 9 | import android.os.Build; 10 | import android.os.Environment; 11 | import android.os.storage.StorageManager; 12 | import android.os.storage.StorageVolume; 13 | import android.provider.DocumentsContract; 14 | import android.provider.MediaStore; 15 | 16 | import androidx.annotation.Nullable; 17 | 18 | import java.io.File; 19 | import java.lang.reflect.Array; 20 | import java.lang.reflect.Method; 21 | import java.text.CharacterIterator; 22 | import java.text.StringCharacterIterator; 23 | import java.util.List; 24 | 25 | /** 26 | * Sources : 27 | * https://stackoverflow.com/a/36162691 28 | * https://stackoverflow.com/a/41520090 29 | */ 30 | public final class FileUtil { 31 | 32 | private static final String PRIMARY_VOLUME_NAME = "primary"; 33 | 34 | @Nullable 35 | public static String getFullPathFromTreeUri(@Nullable final Uri treeUri, Context con) { 36 | if (treeUri == null) return null; 37 | String volumePath = getVolumePath(getVolumeIdFromTreeUri(treeUri), con); 38 | if (volumePath == null) return File.separator; 39 | if (volumePath.endsWith(File.separator)) 40 | volumePath = volumePath.substring(0, volumePath.length() - 1); 41 | 42 | String documentPath = getDocumentPathFromTreeUri(treeUri); 43 | if (documentPath.endsWith(File.separator)) 44 | documentPath = documentPath.substring(0, documentPath.length() - 1); 45 | 46 | if (documentPath.length() > 0) { 47 | if (documentPath.startsWith(File.separator)) 48 | return volumePath + documentPath; 49 | else 50 | return volumePath + File.separator + documentPath; 51 | } else return volumePath; 52 | } 53 | 54 | 55 | private static String getVolumePath(final String volumeId, Context context) { 56 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) 57 | return null; 58 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) 59 | return getVolumePathForAndroid11AndAbove(volumeId, context); 60 | else 61 | return getVolumePathBeforeAndroid11(volumeId, context); 62 | } 63 | 64 | 65 | private static String getVolumePathBeforeAndroid11(final String volumeId, Context context) { 66 | try { 67 | StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); 68 | Class storageVolumeClazz = Class.forName("android.os.storage.StorageVolume"); 69 | Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList"); 70 | Method getUuid = storageVolumeClazz.getMethod("getUuid"); 71 | Method getPath = storageVolumeClazz.getMethod("getPath"); 72 | Method isPrimary = storageVolumeClazz.getMethod("isPrimary"); 73 | Object result = getVolumeList.invoke(mStorageManager); 74 | 75 | final int length = Array.getLength(result); 76 | for (int i = 0; i < length; i++) { 77 | Object storageVolumeElement = Array.get(result, i); 78 | String uuid = (String) getUuid.invoke(storageVolumeElement); 79 | Boolean primary = (Boolean) isPrimary.invoke(storageVolumeElement); 80 | 81 | if (primary && PRIMARY_VOLUME_NAME.equals(volumeId)) // primary volume? 82 | return (String) getPath.invoke(storageVolumeElement); 83 | 84 | if (uuid != null && uuid.equals(volumeId)) // other volumes? 85 | return (String) getPath.invoke(storageVolumeElement); 86 | } 87 | // not found. 88 | return null; 89 | } catch (Exception ex) { 90 | return null; 91 | } 92 | } 93 | 94 | @TargetApi(Build.VERSION_CODES.R) 95 | private static String getVolumePathForAndroid11AndAbove(final String volumeId, Context context) { 96 | try { 97 | StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); 98 | List storageVolumes = mStorageManager.getStorageVolumes(); 99 | for (StorageVolume storageVolume : storageVolumes) { 100 | // primary volume? 101 | if (storageVolume.isPrimary() && PRIMARY_VOLUME_NAME.equals(volumeId)) 102 | return storageVolume.getDirectory().getPath(); 103 | 104 | // other volumes? 105 | String uuid = storageVolume.getUuid(); 106 | if (uuid != null && uuid.equals(volumeId)) 107 | return storageVolume.getDirectory().getPath(); 108 | 109 | } 110 | // not found. 111 | return null; 112 | } catch (Exception ex) { 113 | return null; 114 | } 115 | } 116 | 117 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 118 | private static String getVolumeIdFromTreeUri(final Uri treeUri) { 119 | final String docId = DocumentsContract.getTreeDocumentId(treeUri); 120 | final String[] split = docId.split(":"); 121 | if (split.length > 0) return split[0]; 122 | else return null; 123 | } 124 | 125 | 126 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 127 | private static String getDocumentPathFromTreeUri(final Uri treeUri) { 128 | final String docId = DocumentsContract.getTreeDocumentId(treeUri); 129 | final String[] split = docId.split(":"); 130 | if ((split.length >= 2) && (split[1] != null)) return split[1]; 131 | else return File.separator; 132 | } 133 | 134 | /* 135 | * Gets the file path of the given Uri. 136 | */ 137 | @SuppressLint("NewApi") 138 | public static String getPath(Context context, Uri uri) { 139 | final boolean needToCheckUri = Build.VERSION.SDK_INT >= 19; 140 | String selection = null; 141 | String[] selectionArgs = null; 142 | // Uri is different in versions after KITKAT (Android 4.4), we need to 143 | // deal with different Uris. 144 | if (needToCheckUri && DocumentsContract.isDocumentUri(context.getApplicationContext(), uri)) { 145 | if (isExternalStorageDocument(uri)) { 146 | final String docId = DocumentsContract.getDocumentId(uri); 147 | final String[] split = docId.split(":"); 148 | return Environment.getExternalStorageDirectory() + "/" + split[1]; 149 | } else if (isDownloadsDocument(uri)) { 150 | final String id = DocumentsContract.getDocumentId(uri); 151 | uri = ContentUris.withAppendedId( 152 | Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); 153 | } else if (isMediaDocument(uri)) { 154 | final String docId = DocumentsContract.getDocumentId(uri); 155 | final String[] split = docId.split(":"); 156 | final String type = split[0]; 157 | if ("image".equals(type)) { 158 | uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 159 | } else if ("video".equals(type)) { 160 | uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 161 | } else if ("audio".equals(type)) { 162 | uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 163 | } 164 | selection = "_id=?"; 165 | selectionArgs = new String[]{split[1]}; 166 | } 167 | } 168 | if ("content".equalsIgnoreCase(uri.getScheme())) { 169 | String[] projection = {MediaStore.Images.Media.DATA}; 170 | Cursor cursor = null; 171 | try { 172 | cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); 173 | int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 174 | if (cursor.moveToFirst()) { 175 | return cursor.getString(column_index); 176 | } 177 | } catch (Exception e) { 178 | } 179 | } else if ("file".equalsIgnoreCase(uri.getScheme())) { 180 | return uri.getPath(); 181 | } 182 | return null; 183 | } 184 | 185 | 186 | /** 187 | * @param uri The Uri to check. 188 | * @return Whether the Uri authority is ExternalStorageProvider. 189 | */ 190 | private static boolean isExternalStorageDocument(Uri uri) { 191 | return "com.android.externalstorage.documents".equals(uri.getAuthority()); 192 | } 193 | 194 | /** 195 | * @param uri The Uri to check. 196 | * @return Whether the Uri authority is DownloadsProvider. 197 | */ 198 | private static boolean isDownloadsDocument(Uri uri) { 199 | return "com.android.providers.downloads.documents".equals(uri.getAuthority()); 200 | } 201 | 202 | /** 203 | * @param uri The Uri to check. 204 | * @return Whether the Uri authority is MediaProvider. 205 | */ 206 | private static boolean isMediaDocument(Uri uri) { 207 | return "com.android.providers.media.documents".equals(uri.getAuthority()); 208 | } 209 | 210 | public static String humanReadableByteCountSI(long bytes) { 211 | if (-1000 < bytes && bytes < 1000) { 212 | return bytes + " B"; 213 | } 214 | CharacterIterator ci = new StringCharacterIterator("kMGTPE"); 215 | while (bytes <= -999_950 || bytes >= 999_950) { 216 | bytes /= 1000; 217 | ci.next(); 218 | } 219 | return String.format("%.1f %cB", bytes / 1000.0, ci.current()); 220 | } 221 | } -------------------------------------------------------------------------------- /app/src/main/java/com/aghajari/app/androidr/utils/PermissionUtils.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr.utils; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.UriPermission; 7 | import android.content.pm.PackageManager; 8 | import android.net.Uri; 9 | import android.os.Build; 10 | import android.os.Environment; 11 | import android.provider.DocumentsContract; 12 | import android.provider.Settings; 13 | 14 | import androidx.core.app.ActivityCompat; 15 | import androidx.core.content.ContextCompat; 16 | 17 | import com.aghajari.app.androidr.adapter.FileInterface; 18 | 19 | import java.io.File; 20 | 21 | import static android.Manifest.permission.READ_EXTERNAL_STORAGE; 22 | import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; 23 | import static android.os.Build.VERSION.SDK_INT; 24 | 25 | /** 26 | * A helper class to check and request read/write/manage storage permissions. 27 | * Supports all version of androids. 28 | */ 29 | public final class PermissionUtils { 30 | 31 | public static final String ANDROID = "primary:Android"; 32 | public static final String ANDROID_DATA = "primary:Android/data"; 33 | public static final String ANDROID_OBB = "primary:Android/obb"; 34 | 35 | /** 36 | * @return true if you have the permissions. 37 | */ 38 | public static boolean checkAndRequestPermissions(Activity context, int requestCodeFolder, int requestCodePermission) { 39 | if (!PermissionUtils.checkPermissions(context)) { 40 | PermissionUtils.requestPermissions(context, requestCodePermission); 41 | return false; 42 | } else if (!PermissionUtils.checkAndroidFolderPermission(context, PermissionUtils.ANDROID)) { 43 | PermissionUtils.requestAndroidFolderPermission(context, requestCodeFolder, PermissionUtils.ANDROID); 44 | return false; 45 | } 46 | return true; 47 | } 48 | 49 | /** 50 | * @return true if you have all of the permissions to manage storage. 51 | */ 52 | public static boolean hasAllPermissions(Activity context) { 53 | return PermissionUtils.checkAndroidFolderPermission(context, PermissionUtils.ANDROID) 54 | && PermissionUtils.checkPermissions(context); 55 | } 56 | 57 | /** 58 | * @return true if Android version is higher or equals 30 59 | */ 60 | public static boolean needToUseDocumentFile() { 61 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R; 62 | } 63 | 64 | /** 65 | * @return true if you have access to write/read/manage storage. 66 | */ 67 | public static boolean checkPermissions(Context context) { 68 | if (SDK_INT >= Build.VERSION_CODES.R) { 69 | return Environment.isExternalStorageManager(); 70 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 71 | int result = ContextCompat.checkSelfPermission(context, READ_EXTERNAL_STORAGE); 72 | int result1 = ContextCompat.checkSelfPermission(context, WRITE_EXTERNAL_STORAGE); 73 | return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED; 74 | } 75 | return true; 76 | } 77 | 78 | /** 79 | * request permissions for write/read/manage storage. 80 | */ 81 | public static void requestPermissions(Activity context, int requestCode) { 82 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 83 | Intent i = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); 84 | i.setData(Uri.parse("package:" + context.getPackageName())); 85 | context.startActivityForResult(i, requestCode); 86 | 87 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 88 | 89 | ActivityCompat.requestPermissions(context, new String[]{ 90 | READ_EXTERNAL_STORAGE, 91 | WRITE_EXTERNAL_STORAGE} 92 | , requestCode); 93 | } 94 | } 95 | 96 | /** 97 | * {@link #ANDROID} = /storage/emulated/0/Android 98 | * {@link #ANDROID_DATA} = /storage/emulated/0/Android/data 99 | * {@link #ANDROID_OBB} = /storage/emulated/0/Android/obb 100 | * 101 | * @return android folder uri. 102 | */ 103 | public static Uri getAndroidFolderUri(String id, boolean tree) { 104 | if (tree) 105 | return DocumentsContract.buildTreeDocumentUri("com.android.externalstorage.documents", id); 106 | else 107 | return DocumentsContract.buildDocumentUri("com.android.externalstorage.documents", id); 108 | } 109 | 110 | /** 111 | * @return true if you have access to manage Android folders. 112 | */ 113 | public static boolean checkAndroidFolderPermission(Context context, String id) { 114 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 115 | Uri android_tree_uri = getAndroidFolderUri(id, true); 116 | 117 | for (UriPermission uriPermission : context.getContentResolver().getPersistedUriPermissions()) { 118 | if (uriPermission.getUri().equals(android_tree_uri) && uriPermission.isReadPermission()) 119 | return true; 120 | } 121 | return false; 122 | } else { 123 | return true; 124 | } 125 | } 126 | 127 | /** 128 | * request permission to manage Android folders. 129 | */ 130 | public static void requestAndroidFolderPermission(Activity context, int requestCode, String id) { 131 | Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) 132 | .putExtra("android.provider.extra.SHOW_ADVANCED", true) 133 | .putExtra("android.content.extra.SHOW_ADVANCED", true) 134 | .putExtra(DocumentsContract.EXTRA_INITIAL_URI, getAndroidFolderUri(id, false)); 135 | context.startActivityForResult(i, requestCode); 136 | } 137 | 138 | /** 139 | * Check if needs to get permission for an Android folder (data/obb) 140 | */ 141 | public static boolean needToGetPermission(Context context, FileInterface file) { 142 | return (file.getName().equalsIgnoreCase("obb") 143 | && !checkAndroidFolderPermission(context, ANDROID_OBB)) 144 | || (file.getName().equalsIgnoreCase("data") 145 | && !checkAndroidFolderPermission(context, ANDROID_DATA)); 146 | } 147 | 148 | /** 149 | * Check if needs to get permission for an Android folder (data/obb) 150 | */ 151 | public static boolean needToGetPermission(Context context, File file) { 152 | return (file.getName().equalsIgnoreCase("obb") 153 | && !checkAndroidFolderPermission(context, ANDROID_OBB)) 154 | || (file.getName().equalsIgnoreCase("data") 155 | && !checkAndroidFolderPermission(context, ANDROID_DATA)); 156 | } 157 | 158 | /** 159 | * request permission to manage Android/data or Android/obb 160 | */ 161 | public static void requestAndroidFolderPermission(Activity context, int requestCode, FileInterface file) { 162 | if (file.getName().equalsIgnoreCase("obb")) { 163 | requestAndroidFolderPermission(context, requestCode, ANDROID_OBB); 164 | } else if (file.getName().equalsIgnoreCase("data")) { 165 | requestAndroidFolderPermission(context, requestCode, ANDROID_DATA); 166 | } 167 | } 168 | 169 | public static void grantUriPermission(Context context, Uri uri) { 170 | int flags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION; 171 | context.getContentResolver().takePersistableUriPermission(uri, flags); 172 | context.grantUriPermission(context.getPackageName(), uri, flags); 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/drawable/file.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/drawable/folder.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 23 | 24 | 28 | 29 | 30 | 31 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/rv_item_dir.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 20 | 21 | 25 | 26 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 50 | -------------------------------------------------------------------------------- /app/src/main/res/layout/rv_item_file.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 20 | 21 | 26 | 27 | 28 | 29 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidR 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/aghajari/app/androidr/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.aghajari.app.androidr; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath "com.android.tools.build:gradle:4.0.1" 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | maven { url 'https://maven.google.com' } 18 | jcenter() 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 06 15:03:39 IRST 2021 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-6.3-all.zip 7 | 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /images/Screen1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/images/Screen1.jpg -------------------------------------------------------------------------------- /images/Screen2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aghajari/AndroidDirectoryAccess/dd91c2e71d00c59e0017065507ede91917e7325f/images/Screen2.jpg -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "AndroidR" --------------------------------------------------------------------------------