diff --git a/.gitignore b/.gitignore index 0f885ac..5987e93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,236 @@ -.gradle -/local.properties -/.idea/workspace.xml + +# Created by https://www.gitignore.io/api/windows,linux,osx,intellij,eclipse,java,gradle,android + +### Windows ### +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + + +### OSX ### .DS_Store -/build +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + + +### Java ### +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + + +### Android ### +# Built application files +*.apk +*.ap_ + +# Files for the Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Intellij +*.iml + +### Android Patch ### +gen-external-apklibs diff --git a/.idea/.name b/.idea/.name index 602f413..bd49f95 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -FilePickerDemo \ No newline at end of file +FilePickerLibrary \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 9a8b7e5..96cc43e 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,7 +1,6 @@ - - + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 4761478..4186499 100755 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,10 @@ - - + + + \ No newline at end of file diff --git a/.idea/qaplug_profiles.xml b/.idea/qaplug_profiles.xml new file mode 100644 index 0000000..2cf250a --- /dev/null +++ b/.idea/qaplug_profiles.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/FPlib/.gitignore b/FPlib/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/FPlib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/FPlib/FPlib.iml b/FPlib/FPlib.iml deleted file mode 100755 index f7efe94..0000000 --- a/FPlib/FPlib.iml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/FPlib/build.gradle b/FPlib/build.gradle deleted file mode 100644 index 429eb4c..0000000 --- a/FPlib/build.gradle +++ /dev/null @@ -1,53 +0,0 @@ -buildscript { - repositories { - mavenCentral() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' - } -} - -apply plugin: 'android-sdk-manager' -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' - -group = 'com.github.DeveloperPaul123' - -repositories { - mavenCentral() - maven {url "https://jitpack.io"} -} - -android { - compileSdkVersion 23 - buildToolsVersion '21.1.2' - - defaultConfig { - minSdkVersion 16 - targetSdkVersion 23 - versionName project.VERSION_NAME - versionCode Integer.parseInt(project.VERSION_CODE) - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') -// compile project(':materialfabmenu') - compile 'com.github.DeveloperPaul123:MaterialLibrary:1.0.4' - compile 'com.android.support:appcompat-v7:23.0.1' - compile 'com.android.support:cardview-v7:23.0.1' - compile('com.afollestad.material-dialogs:core:0.8.1.0@aar') { - transitive = true - } - compile 'com.nispok:snackbar:2.10.6' - -} - - diff --git a/FPlib/src/androidTest/java/com/devpaul/filepickerlibrary/ApplicationTest.java b/FPlib/src/androidTest/java/com/devpaul/filepickerlibrary/ApplicationTest.java deleted file mode 100644 index 9feac17..0000000 --- a/FPlib/src/androidTest/java/com/devpaul/filepickerlibrary/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.devpaul.filepickerlibrary; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/FPlib/src/main/res/drawable/fplib_card.xml b/FPlib/src/main/res/drawable/fplib_card.xml deleted file mode 100644 index f0b3657..0000000 --- a/FPlib/src/main/res/drawable/fplib_card.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/app/app.iml b/app/app.iml index 5fef644..6247909 100755 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -12,10 +12,7 @@ - + @@ -50,6 +47,13 @@ + + + + + + + @@ -64,41 +68,41 @@ + + + + + + + - + - - - - - - - + + + + - - - - + - - + - - - + + + + - - - + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 1a310c2..4102b00 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,13 +3,13 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion '21.1.2' + buildToolsVersion '23.0.2' defaultConfig { - applicationId 'com.devpaul.filepicker' + applicationId 'com.github.developerpaul123.filepickerlibrary' minSdkVersion 16 targetSdkVersion 23 - versionCode 1 - versionName '1.0' + versionCode 2 + versionName '3.0' } buildTypes { release { @@ -21,14 +21,8 @@ android { } } -repositories { - mavenCentral() - maven {url "https://jitpack.io"} -} - dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') -// compile 'com.github.DeveloperPaul123:FilePickerLibrary:2.0.1' - compile project(":FPlib") + compile project(':library') compile 'com.github.DeveloperPaul123:MaterialLibrary:1.0.5' } diff --git a/app/src/androidTest/java/com/devpaul/filepicker/ApplicationTest.java b/app/src/androidTest/java/com/devpaul/filepicker/ApplicationTest.java deleted file mode 100644 index 6a93c41..0000000 --- a/app/src/androidTest/java/com/devpaul/filepicker/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.devpaul.filepicker; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 72102bc..3e8f346 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,19 +1,19 @@ - + + android:theme="@style/AppTheme"> + android:name="com.github.developerpaul123.filepickerlibrary.app.MainActivity" + android:label="@string/app_name"> - + - + diff --git a/app/src/main/java/com/devpaul/filepicker/MainActivity.java b/app/src/main/java/com/github/developerpaul123/filepickerlibrary/app/MainActivity.java similarity index 87% rename from app/src/main/java/com/devpaul/filepicker/MainActivity.java rename to app/src/main/java/com/github/developerpaul123/filepickerlibrary/app/MainActivity.java index 0918e47..f3aa151 100644 --- a/app/src/main/java/com/devpaul/filepicker/MainActivity.java +++ b/app/src/main/java/com/github/developerpaul123/filepickerlibrary/app/MainActivity.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.devpaul.filepicker; +package com.github.developerpaul123.filepickerlibrary.app; -import android.app.Activity; import android.app.Fragment; import android.content.Intent; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -27,16 +27,17 @@ import android.view.ViewGroup; import android.widget.Toast; -import com.devpaul.filepickerlibrary.FilePicker; -import com.devpaul.filepickerlibrary.FilePickerActivity; -import com.devpaul.filepickerlibrary.FilePickerBuilder; -import com.devpaul.filepickerlibrary.enums.FileScopeType; -import com.devpaul.filepickerlibrary.enums.FileType; -import com.devpaul.filepickerlibrary.enums.ThemeType; +import com.devpaul.filepicker.R; import com.devpaul.materiallibrary.views.MaterialFlatButton; +import com.github.developerpaul123.filepickerlibrary.FilePicker; +import com.github.developerpaul123.filepickerlibrary.FilePickerActivity; +import com.github.developerpaul123.filepickerlibrary.FilePickerBuilder; +import com.github.developerpaul123.filepickerlibrary.enums.FileScopeType; +import com.github.developerpaul123.filepickerlibrary.enums.FileType; +import com.github.developerpaul123.filepickerlibrary.enums.ThemeType; -public class MainActivity extends Activity { +public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,7 +45,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); if (savedInstanceState == null) { getFragmentManager().beginTransaction() - .add(R.id.container, new PlaceholderFragment()) + .add(R.id.container, new MainActivity.PlaceholderFragment()) .commit(); } } @@ -77,9 +78,24 @@ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + + if (requestCode == FilePickerActivity.REQUEST_DIRECTORY && resultCode == RESULT_OK) { + Toast.makeText(getActivity(), "File Selected: " + data + .getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), + Toast.LENGTH_LONG).show(); + } else if (requestCode == FilePickerActivity.REQUEST_FILE && resultCode == RESULT_OK) { + Toast.makeText(getActivity(), "File Selected: " + data + .getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), + Toast.LENGTH_LONG).show(); + } + super.onActivityResult(requestCode, resultCode, data); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); MaterialFlatButton filePickerActivity = (MaterialFlatButton) rootView.findViewById(R.id.file_picker_activity); @@ -140,7 +156,7 @@ public void onClick(View view) { new FilePickerBuilder(getActivity()).withColor(android.R.color.holo_blue_bright) .withRequestCode(FilePicker.REQUEST_FILE) .withScopeType(FileScopeType.ALL) - .withMimeType(FileType.PNG) + .withMimeType(FileType.JPEG) .useMaterialActivity(true) .launch(); @@ -154,20 +170,5 @@ public void onClick(View view) { }); return rootView; } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - - if(requestCode == FilePickerActivity.REQUEST_DIRECTORY && resultCode == RESULT_OK) { - Toast.makeText(getActivity(), "File Selected: " + data - .getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), - Toast.LENGTH_LONG).show(); - } else if (requestCode == FilePickerActivity.REQUEST_FILE && resultCode == RESULT_OK) { - Toast.makeText(getActivity(), "File Selected: " + data - .getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), - Toast.LENGTH_LONG).show(); - } - super.onActivityResult(requestCode, resultCode, data); - } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e41da7b..eb642dc 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,7 +1,7 @@ - + diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index 74b0cc6..4dd1387 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -1,56 +1,56 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + tools:context="com.github.developerpaul123.filepickerlibrary.app.MainActivity$PlaceholderFragment"> + app:mat_flat_button_color="#303F9F" + app:mat_flat_button_text="@string/file_picker_activity"/> - + android:layout_marginTop="10dip" + app:mat_flat_button_color="#303F9F" + app:mat_flat_button_text="@string/return_file_path"/> + + android:layout_marginTop="10dip" + app:mat_flat_button_color="#303F9F" + app:mat_flat_button_text="@string/file_picker_dialog"/> + android:layout_marginTop="10dip" + app:mat_flat_button_color="#303F9F" + app:mat_flat_button_text="PNG Mime"/> + android:layout_marginTop="10dip" + app:mat_flat_button_color="#303F9F" + app:mat_flat_button_text="Material"/> diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml index 9bfd22c..13a0a81 100644 --- a/app/src/main/res/menu/main.xml +++ b/app/src/main/res/menu/main.xml @@ -1,8 +1,9 @@ - + + android:showAsAction="never" + android:title="@string/action_settings"/> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0fa0054..c8e3888 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -10,9 +10,4 @@ #FF5722 - - diff --git a/build.gradle b/build.gradle index 798ab59..344d3c7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,26 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { - mavenCentral() + jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' - classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' + classpath 'com.android.tools.build:gradle:1.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } - allprojects { - version = VERSION_NAME - group = GROUP repositories { - mavenCentral() - maven { url 'https://dl.bintray.com/drummer-aidan/maven' } - maven {url 'https://jitpack.io'} jcenter() + mavenCentral() + maven { url 'https://jitpack.io' } } -} -apply plugin: 'android-reporting' \ No newline at end of file +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 346bf74..34fb461 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,21 +16,3 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true - -VERSION_NAME=1.4 -VERSION_CODE=6 -GROUP=com.github.developerpaul123.filepickerlibrary - -POM_DESCRIPTION=Android Filepicker Library -POM_URL=https://github.com/DeveloperPaul123/FilePickerLibrary -POM_SCM_URL=https://github.com/DeveloperPaul123/FilePickerLibrary -POM_SCM_CONNECTION=scm:git@github.com:DeveloperPaul123/FilePickerLibrary.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:DeveloperPaul123/FilePickerLibrary.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=developerpaul123 -POM_DEVELOPER_NAME=Paul T - -POM_NAME = filepicker_lib -POM_PACKAGING = pom diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1e1af3c..471ef22 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Oct 03 21:58:58 EDT 2015 +#Wed Feb 24 16:20:47 IRST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/library/build.gradle b/library/build.gradle new file mode 100644 index 0000000..0581b83 --- /dev/null +++ b/library/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 23 + buildToolsVersion '23.0.2' + defaultConfig { + minSdkVersion 16 + targetSdkVersion 23 + versionName '3.0' + versionCode 7 + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + productFlavors { + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:design:23.1.1' + compile 'com.github.DeveloperPaul123:MaterialLibrary:1.0.5' + compile('com.github.afollestad.material-dialogs:core:0.8.5.4@aar') { + transitive = true + } +} + + diff --git a/FPlib/gradle.properties b/library/gradle.properties similarity index 100% rename from FPlib/gradle.properties rename to library/gradle.properties diff --git a/FPlib/proguard-rules.pro b/library/proguard-rules.pro similarity index 100% rename from FPlib/proguard-rules.pro rename to library/proguard-rules.pro diff --git a/FPlib/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml old mode 100755 new mode 100644 similarity index 50% rename from FPlib/src/main/AndroidManifest.xml rename to library/src/main/AndroidManifest.xml index dafb3ba..ca2d732 --- a/FPlib/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,13 +1,17 @@ - + - - + - diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePicker.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePicker.java similarity index 85% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePicker.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePicker.java index 25701d1..1f86283 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePicker.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePicker.java @@ -1,7 +1,8 @@ -package com.devpaul.filepickerlibrary; +package com.github.developerpaul123.filepickerlibrary; import android.Manifest; import android.app.ProgressDialog; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -10,6 +11,8 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; @@ -29,20 +32,17 @@ import android.widget.RelativeLayout; import com.afollestad.materialdialogs.MaterialDialog; -import com.devpaul.filepickerlibrary.adapter.FileRecyclerViewAdapter; -import com.devpaul.filepickerlibrary.enums.FileScopeType; -import com.devpaul.filepickerlibrary.enums.FileType; -import com.devpaul.filepickerlibrary.enums.ThemeType; -import com.devpaul.materiallibrary.views.MaterialFloatingActionButton; -import com.nispok.snackbar.Snackbar; -import com.nispok.snackbar.SnackbarManager; +import com.github.developerpaul123.filepickerlibrary.adapter.FileRecyclerViewAdapter; +import com.github.developerpaul123.filepickerlibrary.enums.FileScopeType; +import com.github.developerpaul123.filepickerlibrary.enums.FileType; +import com.github.developerpaul123.filepickerlibrary.enums.ThemeType; import java.io.File; /** * Created by Paul on 10/8/2015. */ -public class FilePicker extends AppCompatActivity implements NameFileDialogInterface{ +public class FilePicker extends AppCompatActivity implements NameFileDialogInterface { /** * Request code for when you want the file path to a directory. @@ -63,7 +63,7 @@ public class FilePicker extends AppCompatActivity implements NameFileDialogInter /** * Constant value for adding the SCOPE_TYPE enum as an extra to the {@code FilePickerActivity} * {@code Intent} The default is {@code FileType.ALL} see - * {@link com.devpaul.filepickerlibrary.enums.FileScopeType} for other types. + * {@link FileScopeType} for other types. */ public static final String SCOPE_TYPE = "scopeType"; @@ -85,7 +85,7 @@ public class FilePicker extends AppCompatActivity implements NameFileDialogInter public static final String INTENT_EXTRA_FAB_COLOR_ID = "intentExtraFabColorId"; /** - * Constant for retrieving the return file path in {@link #onActivityResult(int, int, android.content.Intent)} + * Constant for retrieving the return file path in {@link #onActivityResult(int, int, Intent)} * If the result code is RESULT_OK then the file path will not be null. This should always be * checked though. *

@@ -106,7 +106,35 @@ public class FilePicker extends AppCompatActivity implements NameFileDialogInter * } */ public static final String FILE_EXTRA_DATA_PATH = "fileExtraPath"; + /** + * Constant used for passing a {@link ThemeType} enum + * to this activity from the calling activity. + */ + public static final String THEME_TYPE = "themeType"; + /** + * Constant used for setting the mime type of the files that the user is supposed to choose. + */ + public static final String MIME_TYPE = "mimeType"; + /** + * Request code for app permissions. + */ + private static final int REQUEST_FOR_READ_EXTERNAL_STORAGE = 101; + private static final OvershootInterpolator interpolator = new OvershootInterpolator(); + /** + * Current toolbar + */ + Toolbar toolbar; + /** + * Floating action button. + */ + FloatingActionButton fab; + + boolean isFabShowing; + /** + * Array of files + */ + File[] files; /** * Recycler view for list of files. */ @@ -123,24 +151,10 @@ public class FilePicker extends AppCompatActivity implements NameFileDialogInter * Container that encloses the two buttons above. */ private LinearLayout buttonContainer; - - /** - * Current toolbar - */ - Toolbar toolbar; - - /** - * Floating action button. - */ - MaterialFloatingActionButton fab; - - boolean isFabShowing; - /** * Relative layout that holds the header. */ private RelativeLayout header; - /** * {@code Animation} for showing the buttonContainer */ @@ -149,10 +163,8 @@ public class FilePicker extends AppCompatActivity implements NameFileDialogInter * {@code Animation} for hiding the buttonContainer */ private Animation slideDown; - private Animation scaleIn; private Animation scaleOut; - /** * {@code File} current directory */ @@ -161,10 +173,6 @@ public class FilePicker extends AppCompatActivity implements NameFileDialogInter * {@code File} the directory one level up from the current one */ private File lastDirectory; - /** - * Array of files - */ - File[] files; /** * {@code FileListAdapter} object */ @@ -173,73 +181,66 @@ public class FilePicker extends AppCompatActivity implements NameFileDialogInter * The currently selected file */ private File currentFile; - private boolean areButtonsShowing; + private final FileRecyclerViewAdapter.Callback callback = new FileRecyclerViewAdapter.Callback() { + @Override + public void onItemClicked(View item, int position) { + + if (position > 0 && position <= files.length - 1) { + currentFile = files[position]; + } + if (adapter.getSelectedPosition() == position) { + hideButtons(); + adapter.setSelectedPosition(-1); + } else { + adapter.setSelectedPosition(position); + showButtons(); + } + } + }; /** - * {@link com.devpaul.filepickerlibrary.enums.FileScopeType} enum + * {@link FileScopeType} enum */ private FileScopeType scopeType; - /** - * {@link com.devpaul.filepickerlibrary.enums.ThemeType} enum for the type of them for this + * {@link ThemeType} enum for the type of them for this * activity. */ private ThemeType themeType; - /** - * Constant used for passing a {@link com.devpaul.filepickerlibrary.enums.ThemeType} enum - * to this activity from the calling activity. - */ - public static final String THEME_TYPE = "themeType"; /** * Actual mime type to be used for file browsing */ private String mimeType; - /** - * Constant used for setting the mime type of the files that the user is supposed to choose. - */ - public static final String MIME_TYPE = "mimeType"; /** * Request code for this activity */ private int requestCode; - /** * {@code Intent} used to send back the data to the calling activity */ private Intent data; - /** * {@code int} used to store the color resource id sent as an extra to this activity. */ private int colorId; - /** * {@code int} used to store the color for the floating action button. */ private int fabColorId; - /** * {@code int} used to store the drawable resource id sent as an extra to this activity. */ private int drawableId; - /** * (@code int) saves the previous first visible item when scrolling, used to make the buttons * disappear */ private int mLastFirstVisibleItem; - /** * (@code Context) saves the context of activity so that you can use it in onClick calls, etc. */ private Context mContext; - - /** - * Request code for app permissions. - */ - private static final int REQUEST_FOR_READ_EXTERNAL_STORAGE = 101; - /** * Layout manager for the Recycler View. */ @@ -250,9 +251,9 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; setContentView(R.layout.material_file_picker_activity_layout); - recyclerView = (RecyclerView) this.findViewById(R.id.file_picker_recycler_view); - toolbar = (Toolbar) this.findViewById(R.id.file_picker_base_toolbar); - fab = (MaterialFloatingActionButton) this.findViewById(R.id.file_picker_floating_action_button); + recyclerView = (RecyclerView) findViewById(R.id.file_picker_recycler_view); + toolbar = (Toolbar) findViewById(R.id.file_picker_base_toolbar); + fab = (FloatingActionButton) findViewById(R.id.file_picker_floating_action_button); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -343,13 +344,13 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { setHeaderBackground(colorId, drawableId); //check for proper permissions. - if(Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); - if(permissionCheck != PackageManager.PERMISSION_GRANTED) { - if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { + if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { //Show permission rationale. - new MaterialDialog.Builder(FilePicker.this) + new MaterialDialog.Builder(this) .title(R.string.file_picker_permission_rationale_dialog_title) .content(R.string.file_picker_permission_rationale_dialog_content) .positiveText(R.string.file_picker_ok) @@ -359,7 +360,7 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { public void onPositive(MaterialDialog dialog) { ActivityCompat.requestPermissions(FilePicker.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE}, + Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_FOR_READ_EXTERNAL_STORAGE); } @@ -370,11 +371,10 @@ public void onNegative(MaterialDialog dialog) { } }) .show(); - } - else { + } else { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE}, + Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_FOR_READ_EXTERNAL_STORAGE); } } @@ -383,45 +383,9 @@ public void onNegative(MaterialDialog dialog) { } } - /** - * Initialize the current directory. - */ - private void init() { - curDirectory = new File(Environment.getExternalStorageDirectory().getPath()); - currentFile = new File(curDirectory.getPath()); - lastDirectory = curDirectory.getParentFile(); - - if (curDirectory.isDirectory()) { - new UpdateFilesTask(this).execute(curDirectory); - } else { - try { - throw new Exception(getString(R.string.file_picker_directory_error)); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { - switch (requestCode) { - //see if we got the permission. - case REQUEST_FOR_READ_EXTERNAL_STORAGE: - if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED - && grantResults[1] == PackageManager.PERMISSION_GRANTED) { - init(); - } - else { - setResult(RESULT_CANCELED); - finish(); - } - return; - } - } - - private static OvershootInterpolator interpolator = new OvershootInterpolator(); /** * Toggles the material floating action button. + * * @param visible */ public void toggleButton(final boolean visible) { @@ -459,20 +423,55 @@ public boolean onPreDraw() { public void onBackPressed() { if (lastDirectory != null && !curDirectory.getPath() .equals(Environment.getExternalStorageDirectory().getPath())) { - new UpdateFilesTask(FilePicker.this).execute(lastDirectory); + new UpdateFilesTask(this).execute(lastDirectory); } else { setResult(RESULT_CANCELED); finish(); } } + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + switch (requestCode) { + //see if we got the permission. + case REQUEST_FOR_READ_EXTERNAL_STORAGE: + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED + && grantResults[1] == PackageManager.PERMISSION_GRANTED) { + init(); + } else { + setResult(RESULT_CANCELED); + finish(); + } + return; + } + } + + /** + * Initialize the current directory. + */ + private void init() { + curDirectory = new File(Environment.getExternalStorageDirectory().getPath()); + currentFile = new File(curDirectory.getPath()); + lastDirectory = curDirectory.getParentFile(); + + if (curDirectory.isDirectory()) { + new UpdateFilesTask(this).execute(curDirectory); + } else { + try { + throw new Exception(getString(R.string.file_picker_directory_error)); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + /** * Initializes all the views in the layout of the activity. */ private void initializeViews() { - buttonContainer = (LinearLayout) this.findViewById(R.id.button_container); + buttonContainer = (LinearLayout) findViewById(R.id.button_container); - selectButton = (Button) this.findViewById(R.id.select_button); + selectButton = (Button) findViewById(R.id.select_button); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -484,9 +483,7 @@ public void onClick(View view) { setResult(RESULT_OK, data); finish(); } else { - SnackbarManager.show(Snackbar.with(FilePicker.this) - .text(R.string.file_picker_snackbar_select_directory_message) - .duration(1500)); + Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_select_directory_message, Snackbar.LENGTH_SHORT).show(); } } else { //request code is for a file if (currentFile.isDirectory()) { @@ -502,10 +499,7 @@ public void onClick(View view) { setResult(RESULT_OK, data); finish(); } else { - SnackbarManager.show(Snackbar.with(FilePicker.this) - .text(String.format(getString(R.string.file_picker_snackbar_select_file_ext_message), - requiredExtension)) - .duration(1500)); + Snackbar.make(getWindow().getDecorView(), String.format(getString(R.string.file_picker_snackbar_select_file_ext_message), requiredExtension), Snackbar.LENGTH_SHORT).show(); } } else { data = new Intent(); @@ -518,7 +512,7 @@ public void onClick(View view) { } }); - openButton = (Button) this.findViewById(R.id.open_button); + openButton = (Button) findViewById(R.id.open_button); openButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -527,20 +521,18 @@ public void onClick(View view) { toolbar.setTitle(curDirectory.getName()); new UpdateFilesTask(FilePicker.this).execute(curDirectory); } else { - Intent newIntent = new Intent(android.content.Intent.ACTION_VIEW); + Intent newIntent = new Intent(Intent.ACTION_VIEW); String file = currentFile.toString(); if (file != null) { newIntent.setDataAndType(Uri.fromFile(currentFile), mimeType); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(newIntent); - } catch (android.content.ActivityNotFoundException e) { - SnackbarManager.show(Snackbar.with(FilePicker.this) - .text(R.string.file_picker_snackbar_no_file_type_handler)); + } catch (ActivityNotFoundException e) { + Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_no_file_type_handler, Snackbar.LENGTH_SHORT).show(); } } else { - SnackbarManager.show(Snackbar.with(FilePicker.this) - .text(R.string.file_picker_snackbar_no_read_type)); + Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_no_read_type, Snackbar.LENGTH_SHORT).show(); } } @@ -579,13 +571,13 @@ private String fileExt(String url) { * Initializes the animations used in this activity. */ private void setUpAnimations() { - slideUp = AnimationUtils.loadAnimation(FilePicker.this, - com.devpaul.filepickerlibrary.R.anim.slide_up); - slideDown = AnimationUtils.loadAnimation(FilePicker.this, - com.devpaul.filepickerlibrary.R.anim.slide_down); - scaleIn = AnimationUtils.loadAnimation(FilePicker.this, + slideUp = AnimationUtils.loadAnimation(this, + R.anim.slide_up); + slideDown = AnimationUtils.loadAnimation(this, + R.anim.slide_down); + scaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in); - scaleOut = AnimationUtils.loadAnimation(FilePicker.this, + scaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out); } @@ -649,37 +641,26 @@ private void setHeaderBackground(int colorResId, int drawableResId) { //TODO } - private FileRecyclerViewAdapter.Callback callback = new FileRecyclerViewAdapter.Callback() { - @Override - public void onItemClicked(View item, int position) { - - if (position > 0 && position <= files.length-1) { - currentFile = files[position]; - } - - if (adapter.getSelectedPosition() == position) { - hideButtons(); - adapter.setSelectedPosition(-1); - } else { - adapter.setSelectedPosition(position); - showButtons(); - } - } - }; - /** * Class that updates the list view with a new array of files. Resets the adapter and the * directory title. */ private class UpdateFilesTask extends AsyncTask { + private final Context mContext; private File[] fileArray; - private Context mContext; private ProgressDialog dialog; private File directory; private UpdateFilesTask(Context context) { - this.mContext = context; + mContext = context; + } + + @Override + protected File[] doInBackground(File... files) { + directory = files[0]; + fileArray = files[0].listFiles(); + return fileArray; } @Override @@ -693,13 +674,6 @@ protected void onPreExecute() { super.onPreExecute(); } - @Override - protected File[] doInBackground(File... files) { - directory = files[0]; - fileArray = files[0].listFiles(); - return fileArray; - } - @Override protected void onPostExecute(File[] localFiles) { files = localFiles; @@ -717,13 +691,13 @@ protected void onPostExecute(File[] localFiles) { // for(int i = 0; i < files.length; i++) { // adapter.addFile(files[i]); // } - if(files != null) { + if (files != null) { adapter = new FileRecyclerViewAdapter(FilePicker.this, files, scopeType, callback); //TODO: Fix this, figure out how to add and remove the header. recyclerView.setAdapter(adapter); } //make sure the button is showing. - if(!isFabShowing) { + if (!isFabShowing) { toggleButton(true); } if (dialog.isShowing()) { diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePickerActivity.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerActivity.java old mode 100755 new mode 100644 similarity index 91% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePickerActivity.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerActivity.java index b7fd816..7d30ab4 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePickerActivity.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerActivity.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package com.devpaul.filepickerlibrary; +package com.github.developerpaul123.filepickerlibrary; import android.Manifest; import android.app.ListActivity; import android.app.ProgressDialog; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -28,6 +29,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.view.MenuItem; @@ -41,14 +43,13 @@ import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; + import com.afollestad.materialdialogs.MaterialDialog; -import com.devpaul.filepickerlibrary.adapter.FileListAdapter; -import com.devpaul.filepickerlibrary.enums.FileScopeType; -import com.devpaul.filepickerlibrary.enums.FileType; -import com.devpaul.filepickerlibrary.enums.ThemeType; import com.devpaul.materiallibrary.views.MaterialFloatingActionButton; -import com.nispok.snackbar.Snackbar; -import com.nispok.snackbar.SnackbarManager; +import com.github.developerpaul123.filepickerlibrary.adapter.FileListAdapter; +import com.github.developerpaul123.filepickerlibrary.enums.FileScopeType; +import com.github.developerpaul123.filepickerlibrary.enums.FileType; +import com.github.developerpaul123.filepickerlibrary.enums.ThemeType; import java.io.File; @@ -78,7 +79,7 @@ public class FilePickerActivity extends ListActivity implements NameFileDialogIn /** * Constant value for adding the SCOPE_TYPE enum as an extra to the {@code FilePickerActivity} * {@code Intent} The default is {@code FileType.ALL} see - * {@link com.devpaul.filepickerlibrary.enums.FileScopeType} for other types. + * {@link FileScopeType} for other types. */ public static final String SCOPE_TYPE = "scopeType"; @@ -100,7 +101,7 @@ public class FilePickerActivity extends ListActivity implements NameFileDialogIn public static final String INTENT_EXTRA_FAB_COLOR_ID = "intentExtraFabColorId"; /** - * Constant for retrieving the return file path in {@link #onActivityResult(int, int, android.content.Intent)} + * Constant for retrieving the return file path in {@link #onActivityResult(int, int, Intent)} * If the result code is RESULT_OK then the file path will not be null. This should always be * checked though. *

@@ -121,7 +122,23 @@ public class FilePickerActivity extends ListActivity implements NameFileDialogIn * } */ public static final String FILE_EXTRA_DATA_PATH = "fileExtraPath"; - + /** + * Constant used for passing a {@link ThemeType} enum + * to this activity from the calling activity. + */ + public static final String THEME_TYPE = "themeType"; + /** + * Constant used for setting the mime type of the files that the user is supposed to choose. + */ + public static final String MIME_TYPE = "mimeType"; + /** + * Request code for app permissions. + */ + private static final int REQUEST_FOR_READ_EXTERNAL_STORAGE = 107; + /** + * Array of files + */ + File[] files; /** * List view for list of files. */ @@ -142,17 +159,14 @@ public class FilePickerActivity extends ListActivity implements NameFileDialogIn * {@code TextView} that titles the view. */ private TextView directoryTitle; - /** * Floating action button. */ private MaterialFloatingActionButton addButton; - /** * Relative layout that holds the header. */ private RelativeLayout header; - /** * {@code Animation} for showing the buttonContainer */ @@ -161,7 +175,6 @@ public class FilePickerActivity extends ListActivity implements NameFileDialogIn * {@code Animation} for hiding the buttonContainer */ private Animation slideDown; - /** * {@code File} current directory */ @@ -170,10 +183,6 @@ public class FilePickerActivity extends ListActivity implements NameFileDialogIn * {@code File} the directory one level up from the current one */ private File lastDirectory; - /** - * Array of files - */ - File[] files; /** * {@code FileListAdapter} object */ @@ -182,73 +191,49 @@ public class FilePickerActivity extends ListActivity implements NameFileDialogIn * The currently selected file */ private File currentFile; - private boolean areButtonsShowing; - /** - * {@link com.devpaul.filepickerlibrary.enums.FileScopeType} enum + * {@link FileScopeType} enum */ private FileScopeType scopeType; - /** - * {@link com.devpaul.filepickerlibrary.enums.ThemeType} enum for the type of them for this + * {@link ThemeType} enum for the type of them for this * activity. */ private ThemeType themeType; - /** - * Constant used for passing a {@link com.devpaul.filepickerlibrary.enums.ThemeType} enum - * to this activity from the calling activity. - */ - public static final String THEME_TYPE = "themeType"; /** * Actual mime type to be used for file browsing */ private String mimeType; - /** - * Constant used for setting the mime type of the files that the user is supposed to choose. - */ - public static final String MIME_TYPE = "mimeType"; /** * Request code for this activity */ private int requestCode; - /** * {@code Intent} used to send back the data to the calling activity */ private Intent data; - /** * {@code int} used to store the color resource id sent as an extra to this activity. */ private int colorId; - /** * {@code int} used to store the color for the floating action button. */ private int fabColorId; - /** * {@code int} used to store the drawable resource id sent as an extra to this activity. */ private int drawableId; - /** * (@code int) saves the previous first visible item when scrolling, used to make the buttons * disappear */ private int mLastFirstVisibleItem; - /** * (@code Context) saves the context of activity so that you can use it in onClick calls, etc. */ private Context mContext; - - /** - * Request code for app permissions. - */ - private static final int REQUEST_FOR_READ_EXTERNAL_STORAGE = 107; - /** * Holder for the list header view. */ @@ -348,7 +333,7 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun if (permissionCheck != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { //Show permission rationale. - new MaterialDialog.Builder(FilePickerActivity.this) + new MaterialDialog.Builder(this) .title(R.string.file_picker_permission_rationale_dialog_title) .content(R.string.file_picker_permission_rationale_dialog_content) .positiveText(R.string.file_picker_ok) @@ -383,23 +368,26 @@ public void onNegative(MaterialDialog dialog) { } } - private void init() { - - curDirectory = new File(Environment.getExternalStorageDirectory().getPath()); - currentFile = new File(curDirectory.getPath()); - lastDirectory = curDirectory.getParentFile(); - - if (curDirectory.isDirectory()) { - new UpdateFilesTask(this).execute(curDirectory); + @Override + public void onBackPressed() { + if (lastDirectory != null && !curDirectory.getPath() + .equals(Environment.getExternalStorageDirectory().getPath())) { + new UpdateFilesTask(this).execute(lastDirectory); } else { - try { - throw new Exception(getString(R.string.file_picker_directory_error)); - } catch (Exception e) { - e.printStackTrace(); - } + setResult(RESULT_CANCELED); + finish(); } } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + setResult(RESULT_CANCELED); + finish(); + } + return super.onOptionsItemSelected(item); + } + @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { @@ -418,14 +406,25 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in } } - @Override - public void onBackPressed() { - if (lastDirectory != null && !curDirectory.getPath() - .equals(Environment.getExternalStorageDirectory().getPath())) { - new UpdateFilesTask(FilePickerActivity.this).execute(lastDirectory); - } else { - setResult(RESULT_CANCELED); - finish(); + /** + * Initializes the animations used in this activity. + */ + private void setUpAnimations() { + slideUp = AnimationUtils.loadAnimation(this, + R.anim.slide_up); + slideDown = AnimationUtils.loadAnimation(this, + R.anim.slide_down); + } + + /** + * Method that hides the sliding panel + */ + private void hideButtons() { + if (areButtonsShowing) { + buttonContainer.clearAnimation(); + buttonContainer.startAnimation(slideDown); + buttonContainer.setVisibility(View.INVISIBLE); + areButtonsShowing = false; } } @@ -458,9 +457,7 @@ public void onClick(View view) { setResult(RESULT_OK, data); finish(); } else { - SnackbarManager.show(Snackbar.with(FilePickerActivity.this) - .text(R.string.file_picker_snackbar_select_directory_message) - .duration(1500)); + Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_select_directory_message, Snackbar.LENGTH_SHORT).show(); } } else { //request code is for a file if (currentFile.isDirectory()) { @@ -476,10 +473,7 @@ public void onClick(View view) { setResult(RESULT_OK, data); finish(); } else { - SnackbarManager.show(Snackbar.with(FilePickerActivity.this) - .text(String.format(getString(R.string.file_picker_snackbar_select_file_ext_message), - requiredExtension)) - .duration(1500)); + Snackbar.make(getWindow().getDecorView(), String.format(getString(R.string.file_picker_snackbar_select_file_ext_message),requiredExtension), Snackbar.LENGTH_SHORT).show(); } } else { data = new Intent(); @@ -502,20 +496,18 @@ public void onClick(View view) { new UpdateFilesTask(FilePickerActivity.this).execute(curDirectory); } else { - Intent newIntent = new Intent(android.content.Intent.ACTION_VIEW); + Intent newIntent = new Intent(Intent.ACTION_VIEW); String file = currentFile.toString(); if (file != null) { newIntent.setDataAndType(Uri.fromFile(currentFile), mimeType); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(newIntent); - } catch (android.content.ActivityNotFoundException e) { - SnackbarManager.show(Snackbar.with(FilePickerActivity.this) - .text(R.string.file_picker_snackbar_no_file_type_handler)); + } catch (ActivityNotFoundException e) { + Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_no_file_type_handler, Snackbar.LENGTH_SHORT).show(); } } else { - SnackbarManager.show(Snackbar.with(FilePickerActivity.this) - .text(R.string.file_picker_snackbar_no_read_type)); + Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_no_read_type, Snackbar.LENGTH_SHORT).show(); } } @@ -528,6 +520,46 @@ public void onClick(View view) { header = (RelativeLayout) findViewById(R.id.header_container); } + /** + * Set the background color of the header + * + * @param colorResId Resource Id of the color + * @param drawableResId Resource Id of the drawable + */ + private void setHeaderBackground(int colorResId, int drawableResId) { + if (drawableResId == -1) { + try { + header.setBackgroundColor(getResources().getColor(colorResId)); + } catch (Resources.NotFoundException e) { + e.printStackTrace(); + } + } else { + try { + header.setBackgroundDrawable(getResources().getDrawable(drawableResId)); + } catch (Resources.NotFoundException e) { + e.printStackTrace(); + } + } + + } + + private void init() { + + curDirectory = new File(Environment.getExternalStorageDirectory().getPath()); + currentFile = new File(curDirectory.getPath()); + lastDirectory = curDirectory.getParentFile(); + + if (curDirectory.isDirectory()) { + new UpdateFilesTask(this).execute(curDirectory); + } else { + try { + throw new Exception(getString(R.string.file_picker_directory_error)); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + /** * Returns the file extension of a file. * @@ -553,25 +585,6 @@ private String fileExt(String url) { } } - /** - * Initializes the animations used in this activity. - */ - private void setUpAnimations() { - slideUp = AnimationUtils.loadAnimation(FilePickerActivity.this, - com.devpaul.filepickerlibrary.R.anim.slide_up); - slideDown = AnimationUtils.loadAnimation(FilePickerActivity.this, - com.devpaul.filepickerlibrary.R.anim.slide_down); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - setResult(RESULT_CANCELED); - finish(); - } - return super.onOptionsItemSelected(item); - } - @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); @@ -603,18 +616,6 @@ private void showButtons() { } } - /** - * Method that hides the sliding panel - */ - private void hideButtons() { - if (areButtonsShowing) { - buttonContainer.clearAnimation(); - buttonContainer.startAnimation(slideDown); - buttonContainer.setVisibility(View.INVISIBLE); - areButtonsShowing = false; - } - } - @Override public void onReturnFileName(String fileName) { @@ -633,28 +634,8 @@ public void onReturnFileName(String fileName) { } } - - /** - * Set the background color of the header - * - * @param colorResId Resource Id of the color - * @param drawableResId Resource Id of the drawable - */ - private void setHeaderBackground(int colorResId, int drawableResId) { - if (drawableResId == -1) { - try { - header.setBackgroundColor(getResources().getColor(colorResId)); - } catch (Resources.NotFoundException e) { - e.printStackTrace(); - } - } else { - try { - header.setBackgroundDrawable(getResources().getDrawable(drawableResId)); - } catch (Resources.NotFoundException e) { - e.printStackTrace(); - } - } - + public ThemeType getThemeType() { + return themeType; } /** @@ -672,23 +653,26 @@ public void setThemeType(ThemeType themeType) { } } - public ThemeType getThemeType() { - return themeType; - } - /** * Class that updates the list view with a new array of files. Resets the adapter and the * directory title. */ private class UpdateFilesTask extends AsyncTask { + private final Context mContext; private File[] fileArray; - private Context mContext; private ProgressDialog dialog; private File directory; private UpdateFilesTask(Context context) { - this.mContext = context; + mContext = context; + } + + @Override + protected File[] doInBackground(File... files) { + directory = files[0]; + fileArray = files[0].listFiles(); + return fileArray; } @Override @@ -702,13 +686,6 @@ protected void onPreExecute() { super.onPreExecute(); } - @Override - protected File[] doInBackground(File... files) { - directory = files[0]; - fileArray = files[0].listFiles(); - return fileArray; - } - @Override protected void onPostExecute(File[] localFiles) { files = localFiles; @@ -732,7 +709,7 @@ protected void onPostExecute(File[] localFiles) { } if (files != null) { adapter = new FileListAdapter(FilePickerActivity.this, files, scopeType); - FilePickerActivity.this.setListAdapter(adapter); + setListAdapter(adapter); } if (dialog.isShowing()) { dialog.dismiss(); diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePickerBuilder.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerBuilder.java similarity index 80% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePickerBuilder.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerBuilder.java index 709c1e3..25fe9d0 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/FilePickerBuilder.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/FilePickerBuilder.java @@ -1,50 +1,53 @@ -package com.devpaul.filepickerlibrary; +package com.github.developerpaul123.filepickerlibrary; import android.app.Activity; import android.content.Intent; import android.support.annotation.ColorRes; -import com.devpaul.filepickerlibrary.enums.FileScopeType; -import com.devpaul.filepickerlibrary.enums.FileType; +import com.github.developerpaul123.filepickerlibrary.enums.FileScopeType; +import com.github.developerpaul123.filepickerlibrary.enums.FileType; /** * Created by Paul on 11/23/2015. */ public class FilePickerBuilder { - private Activity mActivity; + boolean useMaterial; + private final Activity mActivity; private FileScopeType mType; private int requestCode; private int color; private FileType mimeType; - boolean useMaterial; /** * Builder class to build a filepicker activity. + * * @param activity the calling activity. */ public FilePickerBuilder(Activity activity) { - this.color = android.R.color.holo_blue_bright; - this.mType = FileScopeType.ALL; - this.mimeType = FileType.NONE; - this.requestCode = FilePicker.REQUEST_FILE; - this.mActivity = activity; - this.useMaterial =false; + color = android.R.color.holo_blue_bright; + mType = FileScopeType.ALL; + mimeType = FileType.NONE; + requestCode = FilePicker.REQUEST_FILE; + mActivity = activity; + useMaterial = false; } /** * Set the scopetype of the file picker. + * * @param type scope type. Can be DIRECTORIES or ALL. * @return the current builder instance. */ public FilePickerBuilder withScopeType(FileScopeType type) { - this.mType = type; + mType = type; return this; } /** * Set the request code of this. You can request a path to a file or * a directory. + * * @param requestCode the request code can be FilePicker.DIRECTORY or FilePicker.FILE. * @return current instance of the builder. */ @@ -55,6 +58,7 @@ public FilePickerBuilder withRequestCode(int requestCode) { /** * Set the header color with a resource integer. + * * @param color the color resource. * @return current instance of tbe builder. */ @@ -66,42 +70,46 @@ public FilePickerBuilder withColor(@ColorRes int color) { /** * Set the file mime type. The will require the returned file type to match the * mime type. + * * @param type the mime type. * @return current instance of the builder. */ public FilePickerBuilder withMimeType(FileType type) { - this.mimeType = type; + mimeType = type; return this; } /** * Set if you want to use the new material designed file picker. + * * @param use true to use the material version. False otherwise, default is false. * @return current builder instance. */ public FilePickerBuilder useMaterialActivity(boolean use) { - this.useMaterial = use; + useMaterial = use; return this; } + + /** + * Builds and starts the intent with startActivityForResult() uses the + * request code you said as the request code for the activity result. + */ + public void launch() { + Intent intent = build(); + mActivity.startActivityForResult(intent, requestCode); + } + /** * Build the current intent. + * * @return a filepicker intent. */ public Intent build() { - Intent filePicker = new Intent(mActivity, useMaterial ? FilePicker.class: FilePickerActivity.class); + Intent filePicker = new Intent(mActivity, useMaterial ? FilePicker.class : FilePickerActivity.class); filePicker.putExtra(FilePicker.SCOPE_TYPE, mType); filePicker.putExtra(FilePicker.REQUEST_CODE, requestCode); filePicker.putExtra(FilePicker.INTENT_EXTRA_COLOR_ID, color); filePicker.putExtra(FilePicker.MIME_TYPE, mimeType); return filePicker; } - - /** - * Builds and starts the intent with startActivityForResult() uses the - * request code you said as the request code for the activity result. - */ - public void launch() { - Intent intent = this.build(); - mActivity.startActivityForResult(intent, requestCode); - } } diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/NameFileDialog.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/NameFileDialog.java similarity index 97% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/NameFileDialog.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/NameFileDialog.java index df9b753..6a79d3f 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/NameFileDialog.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/NameFileDialog.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.devpaul.filepickerlibrary; +package com.github.developerpaul123.filepickerlibrary; import android.app.Activity; import android.app.Dialog; @@ -32,6 +32,14 @@ public class NameFileDialog extends DialogFragment { private NameFileDialogInterface listener; private EditText fileName; + public static NameFileDialog newInstance() { + + NameFileDialog nfd = new NameFileDialog(); + nfd.setCancelable(false); + return nfd; + + } + @Override public void onAttach(Activity activity) { try { @@ -48,14 +56,6 @@ public void onDetach() { super.onDetach(); } - public static NameFileDialog newInstance() { - - NameFileDialog nfd = new NameFileDialog(); - nfd.setCancelable(false); - return nfd; - - } - @Override public Dialog onCreateDialog(Bundle savedInstanceState) { MaterialDialog.Builder dialog = new MaterialDialog.Builder(getActivity()); @@ -73,6 +73,7 @@ public void onPositive(MaterialDialog dialog) { } dialog.dismiss(); } + @Override public void onNegative(MaterialDialog dialog) { dialog.dismiss(); diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/NameFileDialogInterface.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/NameFileDialogInterface.java similarity index 88% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/NameFileDialogInterface.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/NameFileDialogInterface.java index 2b26df3..e99a711 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/NameFileDialogInterface.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/NameFileDialogInterface.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.devpaul.filepickerlibrary; +package com.github.developerpaul123.filepickerlibrary; /** * Created by Paul Tsouchlos @@ -23,7 +23,8 @@ public interface NameFileDialogInterface { /** * Called when the name file dialog is dismissed returning the inputted name for the new folder. + * * @param fileName */ - public void onReturnFileName(String fileName); + void onReturnFileName(String fileName); } diff --git a/library/src/main/java/com/github/developerpaul123/filepickerlibrary/ScrollAwareFABBehavior.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/ScrollAwareFABBehavior.java new file mode 100644 index 0000000..a03691f --- /dev/null +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/ScrollAwareFABBehavior.java @@ -0,0 +1,42 @@ +package com.github.developerpaul123.filepickerlibrary; + +import android.content.Context; +import android.support.design.widget.CoordinatorLayout; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.view.ViewCompat; +import android.util.AttributeSet; +import android.view.View; + +/** + * Created by Alireza Eskandarpour Shoferi on 2/24/2016. + */ +@SuppressWarnings("unused") +public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior { + + @SuppressWarnings("UnnecessaryCallToSuper") + public ScrollAwareFABBehavior(Context context, AttributeSet attrs) { + super(); + } + + @Override + public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, + FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) { + return (nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL) || + super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, + nestedScrollAxes); + } + + @Override + public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, + View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { + super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, + dyUnconsumed); + + if ((dyConsumed > 0) && (child.getVisibility() == View.VISIBLE)) { + child.hide(); + } else if ((dyConsumed < 0) && (child.getVisibility() != View.VISIBLE)) { + child.show(); + } + } + +} diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/adapter/FileListAdapter.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/adapter/FileListAdapter.java old mode 100755 new mode 100644 similarity index 81% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/adapter/FileListAdapter.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/adapter/FileListAdapter.java index 488a71c..c26e708 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/adapter/FileListAdapter.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/adapter/FileListAdapter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.devpaul.filepickerlibrary.adapter; +package com.github.developerpaul123.filepickerlibrary.adapter; import android.content.Context; import android.graphics.Bitmap; @@ -30,8 +30,8 @@ import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; -import com.devpaul.filepickerlibrary.R; -import com.devpaul.filepickerlibrary.enums.FileScopeType; +import com.github.developerpaul123.filepickerlibrary.R; +import com.github.developerpaul123.filepickerlibrary.enums.FileScopeType; import java.io.ByteArrayOutputStream; import java.io.File; @@ -48,40 +48,120 @@ */ public class FileListAdapter extends BaseAdapter { - private Context mContext; - private List fileList; - private LayoutInflater inflater; + private final Context mContext; + private final List fileList; + private final LayoutInflater inflater; private int selectedPos; private Bitmap bitmap; - private float iconPadding; - private Drawable folderDrawable; + private final float iconPadding; + private final Drawable folderDrawable; - private FileScopeType mFileType; - - private static class ViewHolder { - TextView fileTitle; - TextView fileInfo; - ImageView fileImage; - ImageView fileInfoButton; - } + private final FileScopeType mFileType; public FileListAdapter(Context context, File[] fileArray, FileScopeType type) { - this.mContext = context; - this.fileList = new ArrayList(Arrays.asList(fileArray)); - this.inflater = LayoutInflater.from(mContext); - this.mFileType = type; + mContext = context; + fileList = new ArrayList(Arrays.asList(fileArray)); + inflater = LayoutInflater.from(mContext); + mFileType = type; selectedPos = -1; folderDrawable = mContext.getResources().getDrawable(R.drawable.fplib_ic_folder); iconPadding = mContext.getResources().getDimension(R.dimen.file_picker_lib_default_icon_padding); - if(mFileType == FileScopeType.DIRECTORIES) { - for(int i = 0; i < fileList.size(); i++) { - String extension = fileExt(fileList.get(i).getPath()); - if(extension != null) { - fileList.remove(i); - } + if (mFileType == FileScopeType.DIRECTORIES) { + for (int i = 0; i < fileList.size(); i++) { + String extension = fileExt(fileList.get(i).getPath()); + if (extension != null) { + fileList.remove(i); + } + } + } + } + + /** + * Returns the file extension of a file. + * + * @param url the file path + * @return + */ + private String fileExt(String url) { + if (url.indexOf("?") > -1) { + url = url.substring(0, url.indexOf("?")); + } + if (url.lastIndexOf(".") == -1) { + return null; + } else { + String ext = url.substring(url.lastIndexOf(".")); + if (ext.indexOf("%") > -1) { + ext = ext.substring(0, ext.indexOf("%")); + } + if (ext.indexOf("/") > -1) { + ext = ext.substring(0, ext.indexOf("/")); } + return ext.toLowerCase(); + + } + } + + /** + * From the google examples, decodes a bitmap as a byte array and then resizes it for the required + * width and hieght. + * + * @param picture the picture byte array + * @param reqWidth the required width + * @param reqHeight the required height + * @return a Bitmap + */ + public static Bitmap decodeSampledBitmapFromByteArray(byte[] picture, + int reqWidth, int reqHeight) { + + // First decode with inJustDecodeBounds=true to check dimensions + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeByteArray(picture, 0, picture.length, options); + + // Calculate inSampleSize + options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); + + // Decode bitmap with inSampleSize set + options.inJustDecodeBounds = false; + return BitmapFactory.decodeByteArray(picture, 0, picture.length, options); + } + + public static int calculateInSampleSize( + BitmapFactory.Options options, int reqWidth, int reqHeight) { + // Raw height and width of image + int height = options.outHeight; + int width = options.outWidth; + int inSampleSize = 1; + + if (height > reqHeight || width > reqWidth) { + + // Calculate ratios of height and width to requested height and width + int heightRatio = Math.round((float) height / (float) reqHeight); + int widthRatio = Math.round((float) width / (float) reqWidth); + + // Choose the smallest ratio as inSampleSize value, this will guarantee + // a final image with both dimensions larger than or equal to the + // requested height and width. + inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } + + return inSampleSize; } + + /** + * Encodes a bitmap to a byte array. + * + * @param bitmap the bitmap to compress + * @param format the compression format for the Bitmap + * @return {@code byte[]} object + */ + public static byte[] encodeBitmapToArray(Bitmap bitmap, Bitmap.CompressFormat format) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + bitmap.compress(format, 0, outputStream); + return outputStream.toByteArray(); + + } + @Override public int getCount() { return fileList.size(); @@ -97,34 +177,23 @@ public long getItemId(int i) { return i; } - public void setSelectedPosition(int pos){ - selectedPos = pos; - // inform the view of this change - notifyDataSetChanged(); - } - - public int getSelectedPosition(){ - return selectedPos; - } - - @Override public View getView(int i, View view, ViewGroup viewGroup) { - ViewHolder viewHolder; + FileListAdapter.ViewHolder viewHolder; final int position = i; - if(view == null) { + if (view == null) { view = inflater.inflate(R.layout.file_list_item, null); - viewHolder = new ViewHolder(); + viewHolder = new FileListAdapter.ViewHolder(); viewHolder.fileInfo = (TextView) view.findViewById(R.id.file_item_file_info); viewHolder.fileTitle = (TextView) view.findViewById(R.id.file_item_file_name); viewHolder.fileImage = (ImageView) view.findViewById(R.id.file_item_image_view); viewHolder.fileInfoButton = (ImageView) view.findViewById(R.id.file_item_file_info_button); view.setTag(viewHolder); } else { - viewHolder = (ViewHolder) view.getTag(); + viewHolder = (FileListAdapter.ViewHolder) view.getTag(); } - if(selectedPos == i) { + if (selectedPos == i) { view.setBackgroundColor(mContext.getResources() .getColor(R.color.card_detailing)); } else { @@ -142,29 +211,29 @@ public void onClick(View v) { TextView fileDate = (TextView) customView.findViewById(R.id.file_info_date_created); TextView filePath = (TextView) customView.findViewById(R.id.file_info_path); File file = fileList.get(position); - if(!file.isDirectory()) { + if (!file.isDirectory()) { fileSize.setText(String.format( - mContext.getString(R.string.file_picker_adapter_size_string),file.length())); + mContext.getString(R.string.file_picker_adapter_size_string), file.length())); } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(file.lastModified()); - DateFormat df = SimpleDateFormat.getDateInstance(); + DateFormat df = DateFormat.getDateInstance(); fileDate.setText(String.format(mContext.getString(R.string.file_picker_adapter_last_modified_string), df.format(cal.getTime()))); filePath.setText(String.format(mContext.getString(R.string.file_picker_adapter_file_path_string), file.getAbsolutePath())); new MaterialDialog.Builder(v.getContext()) .title(String.format(mContext.getString(R.string.file_picker_file_info_dialog_file_path), fileList.get(position).getName())) - .customView(customView, true) + .customView(customView, true) .show(); } }); if (mFileType == FileScopeType.ALL) { viewHolder.fileTitle.setText(fileList.get(i).getName()); - if(!fileList.get(i).isDirectory()) { + if (!fileList.get(i).isDirectory()) { viewHolder.fileInfo.setText(String.format(mContext.getString(R.string.file_picker_adapter_file_size_only_string), fileList.get(i).length())); } String fileExt = fileExt(fileList.get(i).toString()); - if(fileList.get(i).isDirectory()) { + if (fileList.get(i).isDirectory()) { viewHolder.fileImage.setBackgroundDrawable(getFileDrawable(R.drawable.fplib_ic_action_file_folder)); } else { if (fileExt != null) { @@ -202,8 +271,8 @@ public void onClick(View v) { } } } - } else if(mFileType == FileScopeType.DIRECTORIES) { - if(fileList.get(i).isDirectory()) { + } else if (mFileType == FileScopeType.DIRECTORIES) { + if (fileList.get(i).isDirectory()) { viewHolder.fileImage.setBackgroundDrawable(folderDrawable); viewHolder.fileTitle.setText(fileList.get(i).getName()); } @@ -213,39 +282,32 @@ public void onClick(View v) { private Drawable getFileDrawable(int fileResource) { Drawable firstLayer = mContext.getResources().getDrawable(fileResource); - LayerDrawable drawable = new LayerDrawable(new Drawable[] { + LayerDrawable drawable = new LayerDrawable(new Drawable[]{ mContext.getResources().getDrawable(R.drawable.fplib_circle), firstLayer }); drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding, - (int)iconPadding, (int)iconPadding); + (int) iconPadding, (int) iconPadding); return drawable; } - /** - * Returns the file extension of a file. - * @param url the file path - * @return - */ - private String fileExt(String url) { - if (url.indexOf("?")>-1) { - url = url.substring(0,url.indexOf("?")); - } - if (url.lastIndexOf(".") == -1) { - return null; - } else { - String ext = url.substring(url.lastIndexOf(".") ); - if (ext.indexOf("%")>-1) { - ext = ext.substring(0,ext.indexOf("%")); - } - if (ext.indexOf("/")>-1) { - ext = ext.substring(0,ext.indexOf("/")); - } - return ext.toLowerCase(); + public int getSelectedPosition() { + return selectedPos; + } - } + public void setSelectedPosition(int pos) { + selectedPos = pos; + // inform the view of this change + notifyDataSetChanged(); + } + + private static class ViewHolder { + TextView fileTitle; + TextView fileInfo; + ImageView fileImage; + ImageView fileInfoButton; } /** @@ -254,14 +316,14 @@ private String fileExt(String url) { private class BitmapWorkerTask extends AsyncTask { private final WeakReference imageViewReference; private byte[] data; - private Bitmap.CompressFormat mFormat; + private final Bitmap.CompressFormat mFormat; public BitmapWorkerTask(ImageView imageView, Bitmap.CompressFormat format) { // Use a WeakReference to ensure the ImageView can be garbage collected imageView.setBackgroundDrawable(imageView.getContext() .getResources().getDrawable(R.drawable.fplib_rectangle)); imageViewReference = new WeakReference(imageView); - this.mFormat = format; + mFormat = format; } // Decode image in background. @@ -269,7 +331,7 @@ public BitmapWorkerTask(ImageView imageView, Bitmap.CompressFormat format) { protected Bitmap doInBackground(File... params) { Bitmap mBitmap = BitmapFactory.decodeFile(params[0].getAbsolutePath()); //check if bitmap is null here. - if(mBitmap != null) { + if (mBitmap != null) { data = encodeBitmapToArray(mBitmap, mFormat); return decodeSampledBitmapFromByteArray(data, 54, 54); } else { @@ -281,7 +343,7 @@ protected Bitmap doInBackground(File... params) { @Override protected void onPostExecute(Bitmap bitmap) { if (imageViewReference.get() != null && bitmap != null) { - final ImageView imageView = imageViewReference.get(); + ImageView imageView = imageViewReference.get(); if (imageView != null) { imageView.setImageBitmap(bitmap); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); @@ -290,96 +352,24 @@ protected void onPostExecute(Bitmap bitmap) { } } - /** - * From the google examples, decodes a bitmap as a byte array and then resizes it for the required - * width and hieght. - * @param picture the picture byte array - * @param reqWidth the required width - * @param reqHeight the required height - * @return a Bitmap - */ - public static Bitmap decodeSampledBitmapFromByteArray(byte[] picture, - int reqWidth, int reqHeight) { - - // First decode with inJustDecodeBounds=true to check dimensions - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapFactory.decodeByteArray(picture, 0, picture.length, options); - - // Calculate inSampleSize - options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); - - // Decode bitmap with inSampleSize set - options.inJustDecodeBounds = false; - return BitmapFactory.decodeByteArray(picture, 0, picture.length, options); - } - - public static int calculateInSampleSize( - BitmapFactory.Options options, int reqWidth, int reqHeight) { - // Raw height and width of image - final int height = options.outHeight; - final int width = options.outWidth; - int inSampleSize = 1; - - if (height > reqHeight || width > reqWidth) { - - // Calculate ratios of height and width to requested height and width - final int heightRatio = Math.round((float) height / (float) reqHeight); - final int widthRatio = Math.round((float) width / (float) reqWidth); - - // Choose the smallest ratio as inSampleSize value, this will guarantee - // a final image with both dimensions larger than or equal to the - // requested height and width. - inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; - } - - return inSampleSize; - } - - /** - * Encodes a bitmap to a byte array. - * @param bitmap the bitmap to compress - * @param format the compression format for the Bitmap - * @return {@code byte[]} object - */ - public static byte[] encodeBitmapToArray(Bitmap bitmap, Bitmap.CompressFormat format) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - bitmap.compress(format, 0, outputStream); - return outputStream.toByteArray(); - - } - private class GetFileSizeTask extends AsyncTask { - private WeakReference textViewWeakReference; - private File file; - private String formatString; + private final WeakReference textViewWeakReference; + private final File file; + private final String formatString; private GetFileSizeTask(TextView textView, File f, String string) { - this.file = f; - this.textViewWeakReference = new WeakReference(textView); - this.formatString = string; - } - - @Override - protected Long doInBackground(Void... params) { - return getDirectorySize(file); - } - - @Override - protected void onPostExecute(Long aLong) { - TextView textView = textViewWeakReference.get(); - if(textView != null) { - textView.setText(String.format(formatString, aLong)); - } + file = f; + textViewWeakReference = new WeakReference(textView); + formatString = string; } private long getDirectorySize(File directory) { File[] files = directory.listFiles(); int size = 0; - if(files != null) { - for(File file: files) { - if(file.isDirectory()) { + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { size += getDirectorySize(file); } else { size += file.length(); @@ -387,7 +377,20 @@ private long getDirectorySize(File directory) { } } return size; + } @Override + protected Long doInBackground(Void... params) { + return getDirectorySize(file); } + + @Override + protected void onPostExecute(Long aLong) { + TextView textView = textViewWeakReference.get(); + if (textView != null) { + textView.setText(String.format(formatString, aLong)); + } + } + + } } diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/adapter/FileRecyclerViewAdapter.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/adapter/FileRecyclerViewAdapter.java similarity index 80% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/adapter/FileRecyclerViewAdapter.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/adapter/FileRecyclerViewAdapter.java index 2620b05..2a2df5a 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/adapter/FileRecyclerViewAdapter.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/adapter/FileRecyclerViewAdapter.java @@ -1,4 +1,4 @@ -package com.devpaul.filepickerlibrary.adapter; +package com.github.developerpaul123.filepickerlibrary.adapter; import android.content.Context; import android.graphics.Bitmap; @@ -15,8 +15,8 @@ import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.Theme; -import com.devpaul.filepickerlibrary.R; -import com.devpaul.filepickerlibrary.enums.FileScopeType; +import com.github.developerpaul123.filepickerlibrary.R; +import com.github.developerpaul123.filepickerlibrary.enums.FileScopeType; import java.io.ByteArrayOutputStream; import java.io.File; @@ -30,106 +30,145 @@ /** * Created by Paul on 10/3/2015. - * + *

* Recycler adapter for the recycler view in the Material Design File Picker activity. */ public class FileRecyclerViewAdapter extends RecyclerView.Adapter { + public static final int TYPE_HEADER = 123; + public static final int TYPE_ITEM = 124; private final Drawable folderDrawable; private int selectedPosition; - private float iconPadding; - private FileScopeType mFileType; - private File[] mFiles; - private View.OnClickListener viewClickListener = new View.OnClickListener() { + private final float iconPadding; + private final FileScopeType mFileType; + private final File[] mFiles; + private final FileRecyclerViewAdapter.Callback mCallback; + private final View.OnClickListener viewClickListener = new View.OnClickListener() { @Override public void onClick(View view) { - if(mCallback != null) { + if (mCallback != null) { mCallback.onItemClicked(view, (Integer) view.getTag(R.id.POSITION_KEY)); } } }; - public static final int TYPE_HEADER = 123; - public static final int TYPE_ITEM = 124; - - private Callback mCallback; + private final View customView; + private final List fileList; + private final Context context; - private View customView; - - public static class FileHeaderViewHolder extends RecyclerView.ViewHolder { - ImageView image; - TextView text; - - public FileHeaderViewHolder(View itemView) { - super(itemView); - image = (ImageView) itemView.findViewById(R.id.file_item_image_view); - text = (TextView) itemView.findViewById(R.id.file_item_file_name); + public FileRecyclerViewAdapter(Context context, File[] files, FileScopeType scopeType, FileRecyclerViewAdapter.Callback callback) { + this.context = context; + mFiles = files; + iconPadding = context.getResources().getDimension(R.dimen.file_picker_lib_default_icon_padding); + mFileType = scopeType; + selectedPosition = -1; + folderDrawable = context.getResources().getDrawable(R.drawable.fplib_ic_folder); + fileList = new ArrayList<>(Arrays.asList(files)); + if (mFileType == FileScopeType.DIRECTORIES) { + for (int i = 0; i < fileList.size(); i++) { + String extension = fileExt(fileList.get(i).getPath()); + if (extension != null) { + fileList.remove(i); + } + } } + mCallback = callback; + customView = LayoutInflater.from(context).inflate(R.layout.file_info_layout, null); } - public static class FileViewHolder extends RecyclerView.ViewHolder { - TextView fileTitle; - TextView fileInfo; - ImageView fileImage; - ImageView fileInfoButton; + /** + * Returns the file extension of a file. + * + * @param url the file path + * @return + */ + private String fileExt(String url) { + if (url.indexOf("?") > -1) { + url = url.substring(0, url.indexOf("?")); + } + if (url.lastIndexOf(".") == -1) { + return null; + } else { + String ext = url.substring(url.lastIndexOf(".")); + if (ext.indexOf("%") > -1) { + ext = ext.substring(0, ext.indexOf("%")); + } + if (ext.indexOf("/") > -1) { + ext = ext.substring(0, ext.indexOf("/")); + } + return ext.toLowerCase(); - public FileViewHolder(View view) { - super(view); - fileInfo = (TextView) view.findViewById(R.id.file_item_file_info); - fileTitle = (TextView) view.findViewById(R.id.file_item_file_name); - fileImage = (ImageView) view.findViewById(R.id.file_item_image_view); - fileInfoButton = (ImageView) view.findViewById(R.id.file_item_file_info_button); } } - public static abstract class Callback { - public void onItemClicked(View item, int position) { + /** + * From the google examples, decodes a bitmap as a byte array and then resizes it for the required + * width and hieght. + * + * @param picture the picture byte array + * @param reqWidth the required width + * @param reqHeight the required height + * @return a Bitmap + */ + public static Bitmap decodeSampledBitmapFromByteArray(byte[] picture, + int reqWidth, int reqHeight) { - } + // First decode with inJustDecodeBounds=true to check dimensions + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeByteArray(picture, 0, picture.length, options); + + // Calculate inSampleSize + options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); + + // Decode bitmap with inSampleSize set + options.inJustDecodeBounds = false; + return BitmapFactory.decodeByteArray(picture, 0, picture.length, options); } - private List fileList; - private Context context; + public static int calculateInSampleSize( + BitmapFactory.Options options, int reqWidth, int reqHeight) { + // Raw height and width of image + int height = options.outHeight; + int width = options.outWidth; + int inSampleSize = 1; - public FileRecyclerViewAdapter(Context context, File[] files, FileScopeType scopeType, Callback callback) { - this.context = context; - this.mFiles = files; - this.iconPadding = context.getResources().getDimension(R.dimen.file_picker_lib_default_icon_padding); - this.mFileType = scopeType; - this.selectedPosition = -1; - this.folderDrawable = context.getResources().getDrawable(R.drawable.fplib_ic_folder); - this.fileList = new ArrayList<>(Arrays.asList(files)); - if(mFileType == FileScopeType.DIRECTORIES) { - for(int i = 0; i < fileList.size(); i++) { - String extension = fileExt(fileList.get(i).getPath()); - if(extension != null) { - fileList.remove(i); - } - } + if (height > reqHeight || width > reqWidth) { + + // Calculate ratios of height and width to requested height and width + int heightRatio = Math.round((float) height / (float) reqHeight); + int widthRatio = Math.round((float) width / (float) reqWidth); + + // Choose the smallest ratio as inSampleSize value, this will guarantee + // a final image with both dimensions larger than or equal to the + // requested height and width. + inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } - this.mCallback = callback; - this.customView = LayoutInflater.from(context).inflate(R.layout.file_info_layout, null); + + return inSampleSize; } + /** + * Encodes a bitmap to a byte array. + * + * @param bitmap the bitmap to compress + * @param format the compression format for the Bitmap + * @return {@code byte[]} object + */ + public static byte[] encodeBitmapToArray(Bitmap bitmap, Bitmap.CompressFormat format) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + bitmap.compress(format, 0, outputStream); + return outputStream.toByteArray(); - @Override - public int getItemViewType(int position) { - if(fileList.size() > 0 && directoryExists(mFiles) && position == 0) { - return TYPE_HEADER; - } else if(fileList.size() == 0 || !directoryExists(mFiles) || position > 0){ - return TYPE_ITEM; - } else { - return TYPE_ITEM; - } } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - if(viewType == TYPE_ITEM) { + if (viewType == TYPE_ITEM) { View v = LayoutInflater.from(context).inflate(R.layout.file_list_item, parent, false); - return new FileViewHolder(v); - } else if(viewType == TYPE_HEADER) { + return new FileRecyclerViewAdapter.FileViewHolder(v); + } else if (viewType == TYPE_HEADER) { View v = LayoutInflater.from(context).inflate(R.layout.file_list_header_view, parent, false); - return new FileHeaderViewHolder(v); + return new FileRecyclerViewAdapter.FileHeaderViewHolder(v); } throw new RuntimeException(context.getString(R.string.file_picker_recycler_adapter_view_holder_type_error)); @@ -139,13 +178,13 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { File file = getItem(position); - if(holder instanceof FileViewHolder) { - FileViewHolder viewHolder = (FileViewHolder) holder; + if (holder instanceof FileRecyclerViewAdapter.FileViewHolder) { + FileRecyclerViewAdapter.FileViewHolder viewHolder = (FileRecyclerViewAdapter.FileViewHolder) holder; viewHolder.fileTitle.setText(file.getName()); viewHolder.itemView.setTag(R.id.POSITION_KEY, position); viewHolder.itemView.setOnClickListener(viewClickListener); - if(selectedPosition == position) { + if (selectedPosition == position) { viewHolder.itemView.setBackgroundColor(context.getResources() .getColor(R.color.card_detailing)); } else { @@ -170,7 +209,7 @@ public void onClick(View v) { } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(file.lastModified()); - DateFormat df = SimpleDateFormat.getDateInstance(); + DateFormat df = DateFormat.getDateInstance(); fileDate.setText(String.format(context.getString(R.string.file_picker_adapter_last_modified_string), df.format(cal.getTime()))); filePath.setText(String.format(context.getString(R.string.file_picker_adapter_file_path_string), @@ -186,12 +225,12 @@ public void onClick(View v) { if (mFileType == FileScopeType.ALL) { viewHolder.fileTitle.setText(fileList.get(i).getName()); - if(!fileList.get(i).isDirectory()) { + if (!fileList.get(i).isDirectory()) { viewHolder.fileInfo.setText(String.format(context.getString(R.string.file_picker_adapter_file_size_only_string), fileList.get(i).length())); } String fileExt = fileExt(fileList.get(i).toString()); - if(fileList.get(i).isDirectory()) { + if (fileList.get(i).isDirectory()) { viewHolder.fileImage.setBackgroundDrawable(getFileDrawable(R.drawable.fplib_ic_action_file_folder)); } else { if (fileExt != null) { @@ -229,29 +268,68 @@ public void onClick(View v) { } } } - } else if(mFileType == FileScopeType.DIRECTORIES) { - if(fileList.get(i).isDirectory()) { + } else if (mFileType == FileScopeType.DIRECTORIES) { + if (fileList.get(i).isDirectory()) { viewHolder.fileImage.setBackgroundDrawable(folderDrawable); viewHolder.fileTitle.setText(fileList.get(i).getName()); } } - } else if(holder instanceof FileHeaderViewHolder) { - FileHeaderViewHolder fileHeaderViewHolder = (FileHeaderViewHolder) holder; + } else if (holder instanceof FileRecyclerViewAdapter.FileHeaderViewHolder) { + FileRecyclerViewAdapter.FileHeaderViewHolder fileHeaderViewHolder = (FileRecyclerViewAdapter.FileHeaderViewHolder) holder; fileHeaderViewHolder.text.setText("Folders"); fileHeaderViewHolder.image.setBackgroundColor(context.getResources().getColor(android.R.color.background_light)); } } + @Override + public int getItemViewType(int position) { + if (fileList.size() > 0 && directoryExists(mFiles) && position == 0) { + return TYPE_HEADER; + } else if (fileList.size() == 0 || !directoryExists(mFiles) || position > 0) { + return TYPE_ITEM; + } else { + return TYPE_ITEM; + } + } + @Override public int getItemCount() { return fileList.size(); } + /** + * Checks if the files contain a directory. + * + * @param files the files. + * @return a boolean, true if there is a file that is a directory. + */ + public boolean directoryExists(File[] files) { + for (int i = 0; i < files.length; i++) { + if (files[i].isDirectory()) { + return true; + } + } + return false; + } + public File getItem(int i) { return fileList.get(i); } + private Drawable getFileDrawable(int fileResource) { + Drawable firstLayer = context.getResources().getDrawable(fileResource); + LayerDrawable drawable = new LayerDrawable(new Drawable[]{ + context.getResources().getDrawable(R.drawable.fplib_circle), + firstLayer + }); + + drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding, + (int) iconPadding, (int) iconPadding); + + return drawable; + } + public void addFile(File file) { fileList.add(file); notifyDataSetChanged(); @@ -262,65 +340,45 @@ public void removeFile(int position) { notifyDataSetChanged(); } - public void setSelectedPosition(int i) { - this.selectedPosition = i; - notifyDataSetChanged(); - } - public int getSelectedPosition() { - return this.selectedPosition; + return selectedPosition; } - private Drawable getFileDrawable(int fileResource) { - Drawable firstLayer = context.getResources().getDrawable(fileResource); - LayerDrawable drawable = new LayerDrawable(new Drawable[] { - context.getResources().getDrawable(R.drawable.fplib_circle), - firstLayer - }); + public void setSelectedPosition(int i) { + selectedPosition = i; + notifyDataSetChanged(); + } - drawable.setLayerInset(1, (int) iconPadding, (int) iconPadding, - (int)iconPadding, (int)iconPadding); + public static class FileHeaderViewHolder extends RecyclerView.ViewHolder { + ImageView image; + TextView text; - return drawable; + public FileHeaderViewHolder(View itemView) { + super(itemView); + image = (ImageView) itemView.findViewById(R.id.file_item_image_view); + text = (TextView) itemView.findViewById(R.id.file_item_file_name); + } } - /** - * Returns the file extension of a file. - * @param url the file path - * @return - */ - private String fileExt(String url) { - if (url.indexOf("?")>-1) { - url = url.substring(0,url.indexOf("?")); - } - if (url.lastIndexOf(".") == -1) { - return null; - } else { - String ext = url.substring(url.lastIndexOf(".") ); - if (ext.indexOf("%")>-1) { - ext = ext.substring(0,ext.indexOf("%")); - } - if (ext.indexOf("/")>-1) { - ext = ext.substring(0,ext.indexOf("/")); - } - return ext.toLowerCase(); + public static class FileViewHolder extends RecyclerView.ViewHolder { + TextView fileTitle; + TextView fileInfo; + ImageView fileImage; + ImageView fileInfoButton; + public FileViewHolder(View view) { + super(view); + fileInfo = (TextView) view.findViewById(R.id.file_item_file_info); + fileTitle = (TextView) view.findViewById(R.id.file_item_file_name); + fileImage = (ImageView) view.findViewById(R.id.file_item_image_view); + fileInfoButton = (ImageView) view.findViewById(R.id.file_item_file_info_button); } } - /** - * Checks if the files contain a directory. - * - * @param files the files. - * @return a boolean, true if there is a file that is a directory. - */ - public boolean directoryExists(File[] files) { - for (int i = 0; i < files.length; i++) { - if (files[i].isDirectory()) { - return true; - } + public abstract static class Callback { + public void onItemClicked(View item, int position) { + } - return false; } /** @@ -329,14 +387,14 @@ public boolean directoryExists(File[] files) { private class BitmapWorkerTask extends AsyncTask { private final WeakReference imageViewReference; private byte[] data; - private Bitmap.CompressFormat mFormat; + private final Bitmap.CompressFormat mFormat; public BitmapWorkerTask(ImageView imageView, Bitmap.CompressFormat format) { // Use a WeakReference to ensure the ImageView can be garbage collected imageView.setBackgroundDrawable(imageView.getContext() .getResources().getDrawable(R.drawable.fplib_rectangle)); imageViewReference = new WeakReference(imageView); - this.mFormat = format; + mFormat = format; } // Decode image in background. @@ -344,7 +402,7 @@ public BitmapWorkerTask(ImageView imageView, Bitmap.CompressFormat format) { protected Bitmap doInBackground(File... params) { Bitmap mBitmap = BitmapFactory.decodeFile(params[0].getAbsolutePath()); //check if bitmap is null here. - if(mBitmap != null) { + if (mBitmap != null) { data = encodeBitmapToArray(mBitmap, mFormat); return decodeSampledBitmapFromByteArray(data, 54, 54); } else { @@ -356,7 +414,7 @@ protected Bitmap doInBackground(File... params) { @Override protected void onPostExecute(Bitmap bitmap) { if (imageViewReference.get() != null && bitmap != null) { - final ImageView imageView = imageViewReference.get(); + ImageView imageView = imageViewReference.get(); if (imageView != null) { imageView.setImageBitmap(bitmap); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); @@ -365,78 +423,30 @@ protected void onPostExecute(Bitmap bitmap) { } } - /** - * From the google examples, decodes a bitmap as a byte array and then resizes it for the required - * width and hieght. - * @param picture the picture byte array - * @param reqWidth the required width - * @param reqHeight the required height - * @return a Bitmap - */ - public static Bitmap decodeSampledBitmapFromByteArray(byte[] picture, - int reqWidth, int reqHeight) { - - // First decode with inJustDecodeBounds=true to check dimensions - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapFactory.decodeByteArray(picture, 0, picture.length, options); - - // Calculate inSampleSize - options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); - - // Decode bitmap with inSampleSize set - options.inJustDecodeBounds = false; - return BitmapFactory.decodeByteArray(picture, 0, picture.length, options); - } - - public static int calculateInSampleSize( - BitmapFactory.Options options, int reqWidth, int reqHeight) { - // Raw height and width of image - final int height = options.outHeight; - final int width = options.outWidth; - int inSampleSize = 1; - - if (height > reqHeight || width > reqWidth) { - - // Calculate ratios of height and width to requested height and width - final int heightRatio = Math.round((float) height / (float) reqHeight); - final int widthRatio = Math.round((float) width / (float) reqWidth); - - // Choose the smallest ratio as inSampleSize value, this will guarantee - // a final image with both dimensions larger than or equal to the - // requested height and width. - inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; - } - - return inSampleSize; - } - - /** - * Encodes a bitmap to a byte array. - * @param bitmap the bitmap to compress - * @param format the compression format for the Bitmap - * @return {@code byte[]} object - */ - public static byte[] encodeBitmapToArray(Bitmap bitmap, Bitmap.CompressFormat format) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - bitmap.compress(format, 0, outputStream); - return outputStream.toByteArray(); - - } - private class GetFileSizeTask extends AsyncTask { - private WeakReference textViewWeakReference; - private File file; - private String formatString; + private final WeakReference textViewWeakReference; + private final File file; + private final String formatString; private GetFileSizeTask(TextView textView, File f, String string) { - this.file = f; - this.textViewWeakReference = new WeakReference(textView); - this.formatString = string; + file = f; + textViewWeakReference = new WeakReference(textView); + formatString = string; } - @Override + private long getDirectorySize(File directory) { + File[] files = directory.listFiles(); + int size = 0; + for (File file : files) { + if (file.isDirectory()) { + size += getDirectorySize(file); + } else { + size += file.length(); + } + } + return size; + } @Override protected Long doInBackground(Void... params) { return getDirectorySize(file); } @@ -444,22 +454,11 @@ protected Long doInBackground(Void... params) { @Override protected void onPostExecute(Long aLong) { TextView textView = textViewWeakReference.get(); - if(textView != null) { + if (textView != null) { textView.setText(String.format(formatString, aLong)); } } - private long getDirectorySize(File directory) { - File[] files = directory.listFiles(); - int size = 0; - for(File file: files) { - if(file.isDirectory()) { - size += getDirectorySize(file); - } else { - size += file.length(); - } - } - return size; - } + } } diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/FileScopeType.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/FileScopeType.java similarity index 90% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/FileScopeType.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/FileScopeType.java index 9df7f69..449cabb 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/FileScopeType.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/FileScopeType.java @@ -14,13 +14,12 @@ * limitations under the License. */ -package com.devpaul.filepickerlibrary.enums; +package com.github.developerpaul123.filepickerlibrary.enums; /** * An enum that has two possible values, {@code ALL} or {@code DIRECTORIES} */ public enum FileScopeType { - ALL - ,DIRECTORIES + ALL, DIRECTORIES } diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/FileType.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/FileType.java similarity index 92% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/FileType.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/FileType.java index dcf12bc..7998653 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/FileType.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/FileType.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.devpaul.filepickerlibrary.enums; +package com.github.developerpaul123.filepickerlibrary.enums; /** * Created by Paul Tsouchlos @@ -25,7 +25,7 @@ public enum FileType { DOC("application/msword"), DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"), HTML("text/html"), TXT("text/plain"), PDF("application/pdf"); - private String mimeType; + private final String mimeType; FileType(String mimeType) { this.mimeType = mimeType; diff --git a/FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/ThemeType.java b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/ThemeType.java similarity index 86% rename from FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/ThemeType.java rename to library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/ThemeType.java index 93e38a7..6e64ada 100644 --- a/FPlib/src/main/java/com/devpaul/filepickerlibrary/enums/ThemeType.java +++ b/library/src/main/java/com/github/developerpaul123/filepickerlibrary/enums/ThemeType.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.devpaul.filepickerlibrary.enums; +package com.github.developerpaul123.filepickerlibrary.enums; /** * Created by Paul Tsouchlos */ public enum ThemeType { - DIALOG,ACTIVITY,DIALOG_NO_ACTION_BAR + DIALOG, ACTIVITY, DIALOG_NO_ACTION_BAR } diff --git a/FPlib/src/main/res/anim/rotate_and_fade_in.xml b/library/src/main/res/anim/rotate_and_fade_in.xml similarity index 84% rename from FPlib/src/main/res/anim/rotate_and_fade_in.xml rename to library/src/main/res/anim/rotate_and_fade_in.xml index 4d98774..225b2ab 100644 --- a/FPlib/src/main/res/anim/rotate_and_fade_in.xml +++ b/library/src/main/res/anim/rotate_and_fade_in.xml @@ -19,24 +19,24 @@ + android:pivotY="50%" + android:toDegrees="720"/> + android:toAlpha="1.0"/> + android:toXScale="100%" + android:toYScale="100%"/> \ No newline at end of file diff --git a/FPlib/src/main/res/anim/rotate_and_fade_out.xml b/library/src/main/res/anim/rotate_and_fade_out.xml similarity index 85% rename from FPlib/src/main/res/anim/rotate_and_fade_out.xml rename to library/src/main/res/anim/rotate_and_fade_out.xml index a92df24..eb7694c 100644 --- a/FPlib/src/main/res/anim/rotate_and_fade_out.xml +++ b/library/src/main/res/anim/rotate_and_fade_out.xml @@ -19,24 +19,24 @@ + android:pivotY="50%" + android:toDegrees="720"/> + android:toAlpha="0"/> + android:toXScale="0%" + android:toYScale="0%"/> \ No newline at end of file diff --git a/FPlib/src/main/res/anim/scale_in.xml b/library/src/main/res/anim/scale_in.xml similarity index 81% rename from FPlib/src/main/res/anim/scale_in.xml rename to library/src/main/res/anim/scale_in.xml index 3bf05f2..e98ef87 100644 --- a/FPlib/src/main/res/anim/scale_in.xml +++ b/library/src/main/res/anim/scale_in.xml @@ -1,11 +1,11 @@ + android:pivotY="50%" + android:toXScale="100%" + android:toYScale="100%"/> \ No newline at end of file diff --git a/FPlib/src/main/res/anim/scale_out.xml b/library/src/main/res/anim/scale_out.xml similarity index 81% rename from FPlib/src/main/res/anim/scale_out.xml rename to library/src/main/res/anim/scale_out.xml index 5e2438f..e07981d 100644 --- a/FPlib/src/main/res/anim/scale_out.xml +++ b/library/src/main/res/anim/scale_out.xml @@ -2,11 +2,11 @@ + android:toXScale="0%" + android:toYScale="0%"/> \ No newline at end of file diff --git a/FPlib/src/main/res/anim/slide_down.xml b/library/src/main/res/anim/slide_down.xml similarity index 90% rename from FPlib/src/main/res/anim/slide_down.xml rename to library/src/main/res/anim/slide_down.xml index 76d7f82..fe06d02 100644 --- a/FPlib/src/main/res/anim/slide_down.xml +++ b/library/src/main/res/anim/slide_down.xml @@ -19,14 +19,14 @@ + android:fromYDelta="0%" + android:interpolator="@android:interpolator/decelerate_cubic" + android:toYDelta="200%"/> + android:toAlpha="0"/> \ No newline at end of file diff --git a/FPlib/src/main/res/anim/slide_up.xml b/library/src/main/res/anim/slide_up.xml similarity index 90% rename from FPlib/src/main/res/anim/slide_up.xml rename to library/src/main/res/anim/slide_up.xml index 6173797..f17255d 100644 --- a/FPlib/src/main/res/anim/slide_up.xml +++ b/library/src/main/res/anim/slide_up.xml @@ -19,14 +19,14 @@ + android:fromYDelta="200%" + android:interpolator="@android:interpolator/decelerate_cubic" + android:toYDelta="0%"/> + android:toAlpha="1.0"/> \ No newline at end of file diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_action_content_new.png b/library/src/main/res/drawable-hdpi/fplib_ic_action_content_new.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_action_content_new.png rename to library/src/main/res/drawable-hdpi/fplib_ic_action_content_new.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_action_file_folder.png b/library/src/main/res/drawable-hdpi/fplib_ic_action_file_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_action_file_folder.png rename to library/src/main/res/drawable-hdpi/fplib_ic_action_file_folder.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_action_info.png b/library/src/main/res/drawable-hdpi/fplib_ic_action_info.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_action_info.png rename to library/src/main/res/drawable-hdpi/fplib_ic_action_info.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_action_navigation_back.png b/library/src/main/res/drawable-hdpi/fplib_ic_action_navigation_back.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_action_navigation_back.png rename to library/src/main/res/drawable-hdpi/fplib_ic_action_navigation_back.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_collections_collection.png b/library/src/main/res/drawable-hdpi/fplib_ic_collections_collection.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_collections_collection.png rename to library/src/main/res/drawable-hdpi/fplib_ic_collections_collection.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_default_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_default_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_default_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_default_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_doc_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_doc_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_doc_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_doc_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_docx_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_docx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_docx_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_docx_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_file_audio.png b/library/src/main/res/drawable-hdpi/fplib_ic_file_audio.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_file_audio.png rename to library/src/main/res/drawable-hdpi/fplib_ic_file_audio.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_file_html.png b/library/src/main/res/drawable-hdpi/fplib_ic_file_html.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_file_html.png rename to library/src/main/res/drawable-hdpi/fplib_ic_file_html.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_file_video.png b/library/src/main/res/drawable-hdpi/fplib_ic_file_video.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_file_video.png rename to library/src/main/res/drawable-hdpi/fplib_ic_file_video.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_folder.png b/library/src/main/res/drawable-hdpi/fplib_ic_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_folder.png rename to library/src/main/res/drawable-hdpi/fplib_ic_folder.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_html_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_html_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_html_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_html_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_pdf_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_pdf_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_pdf_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_pdf_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_txt_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_txt_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_txt_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_txt_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_xls_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_xls_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_xls_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_xls_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_xlsx_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_xlsx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_xlsx_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_xlsx_file.png diff --git a/FPlib/src/main/res/drawable-hdpi/fplib_ic_xml_file.png b/library/src/main/res/drawable-hdpi/fplib_ic_xml_file.png similarity index 100% rename from FPlib/src/main/res/drawable-hdpi/fplib_ic_xml_file.png rename to library/src/main/res/drawable-hdpi/fplib_ic_xml_file.png diff --git a/library/src/main/res/drawable-hdpi/ic_plus.png b/library/src/main/res/drawable-hdpi/ic_plus.png new file mode 100644 index 0000000..a899d6f Binary files /dev/null and b/library/src/main/res/drawable-hdpi/ic_plus.png differ diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_action_content_new.png b/library/src/main/res/drawable-mdpi/fplib_ic_action_content_new.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_action_content_new.png rename to library/src/main/res/drawable-mdpi/fplib_ic_action_content_new.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_action_file_folder.png b/library/src/main/res/drawable-mdpi/fplib_ic_action_file_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_action_file_folder.png rename to library/src/main/res/drawable-mdpi/fplib_ic_action_file_folder.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_action_info.png b/library/src/main/res/drawable-mdpi/fplib_ic_action_info.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_action_info.png rename to library/src/main/res/drawable-mdpi/fplib_ic_action_info.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_action_navigation_back.png b/library/src/main/res/drawable-mdpi/fplib_ic_action_navigation_back.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_action_navigation_back.png rename to library/src/main/res/drawable-mdpi/fplib_ic_action_navigation_back.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_collections_collection.png b/library/src/main/res/drawable-mdpi/fplib_ic_collections_collection.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_collections_collection.png rename to library/src/main/res/drawable-mdpi/fplib_ic_collections_collection.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_default_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_default_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_default_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_default_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_doc_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_doc_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_doc_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_doc_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_docx_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_docx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_docx_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_docx_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_file_audio.png b/library/src/main/res/drawable-mdpi/fplib_ic_file_audio.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_file_audio.png rename to library/src/main/res/drawable-mdpi/fplib_ic_file_audio.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_file_html.png b/library/src/main/res/drawable-mdpi/fplib_ic_file_html.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_file_html.png rename to library/src/main/res/drawable-mdpi/fplib_ic_file_html.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_file_video.png b/library/src/main/res/drawable-mdpi/fplib_ic_file_video.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_file_video.png rename to library/src/main/res/drawable-mdpi/fplib_ic_file_video.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_folder.png b/library/src/main/res/drawable-mdpi/fplib_ic_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_folder.png rename to library/src/main/res/drawable-mdpi/fplib_ic_folder.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_html_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_html_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_html_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_html_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_pdf_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_pdf_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_pdf_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_pdf_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_txt_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_txt_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_txt_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_txt_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_xls_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_xls_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_xls_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_xls_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_xlsx_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_xlsx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_xlsx_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_xlsx_file.png diff --git a/FPlib/src/main/res/drawable-mdpi/fplib_ic_xml_file.png b/library/src/main/res/drawable-mdpi/fplib_ic_xml_file.png similarity index 100% rename from FPlib/src/main/res/drawable-mdpi/fplib_ic_xml_file.png rename to library/src/main/res/drawable-mdpi/fplib_ic_xml_file.png diff --git a/library/src/main/res/drawable-mdpi/ic_plus.png b/library/src/main/res/drawable-mdpi/ic_plus.png new file mode 100644 index 0000000..02a62e2 Binary files /dev/null and b/library/src/main/res/drawable-mdpi/ic_plus.png differ diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_content_new.png b/library/src/main/res/drawable-xhdpi/fplib_ic_action_content_new.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_content_new.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_action_content_new.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_file_folder.png b/library/src/main/res/drawable-xhdpi/fplib_ic_action_file_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_file_folder.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_action_file_folder.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_info.png b/library/src/main/res/drawable-xhdpi/fplib_ic_action_info.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_info.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_action_info.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_navigation_back.png b/library/src/main/res/drawable-xhdpi/fplib_ic_action_navigation_back.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_action_navigation_back.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_action_navigation_back.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_collections_collection.png b/library/src/main/res/drawable-xhdpi/fplib_ic_collections_collection.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_collections_collection.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_collections_collection.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_default_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_default_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_default_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_default_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_doc_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_doc_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_doc_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_doc_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_docx_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_docx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_docx_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_docx_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_file_audio.png b/library/src/main/res/drawable-xhdpi/fplib_ic_file_audio.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_file_audio.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_file_audio.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_file_html.png b/library/src/main/res/drawable-xhdpi/fplib_ic_file_html.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_file_html.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_file_html.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_file_video.png b/library/src/main/res/drawable-xhdpi/fplib_ic_file_video.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_file_video.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_file_video.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_folder.png b/library/src/main/res/drawable-xhdpi/fplib_ic_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_folder.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_folder.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_html_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_html_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_html_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_html_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_pdf_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_pdf_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_pdf_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_pdf_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_txt_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_txt_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_txt_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_txt_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_xls_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_xls_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_xls_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_xls_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_xlsx_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_xlsx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_xlsx_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_xlsx_file.png diff --git a/FPlib/src/main/res/drawable-xhdpi/fplib_ic_xml_file.png b/library/src/main/res/drawable-xhdpi/fplib_ic_xml_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xhdpi/fplib_ic_xml_file.png rename to library/src/main/res/drawable-xhdpi/fplib_ic_xml_file.png diff --git a/library/src/main/res/drawable-xhdpi/ic_plus.png b/library/src/main/res/drawable-xhdpi/ic_plus.png new file mode 100644 index 0000000..906daaf Binary files /dev/null and b/library/src/main/res/drawable-xhdpi/ic_plus.png differ diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_content_new.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_action_content_new.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_content_new.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_action_content_new.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_file_folder.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_action_file_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_file_folder.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_action_file_folder.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_info.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_action_info.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_info.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_action_info.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_navigation_back.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_action_navigation_back.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_action_navigation_back.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_action_navigation_back.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_collections_collection.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_collections_collection.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_collections_collection.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_collections_collection.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_default_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_default_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_default_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_default_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_doc_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_doc_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_doc_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_doc_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_docx_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_docx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_docx_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_docx_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_file_audio.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_file_audio.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_file_audio.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_file_audio.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_file_html.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_file_html.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_file_html.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_file_html.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_file_video.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_file_video.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_file_video.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_file_video.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_folder.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_folder.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_folder.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_folder.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_html_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_html_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_html_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_html_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_pdf_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_pdf_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_pdf_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_pdf_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_txt_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_txt_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_txt_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_txt_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_xls_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_xls_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_xls_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_xls_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_xlsx_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_xlsx_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_xlsx_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_xlsx_file.png diff --git a/FPlib/src/main/res/drawable-xxhdpi/fplib_ic_xml_file.png b/library/src/main/res/drawable-xxhdpi/fplib_ic_xml_file.png similarity index 100% rename from FPlib/src/main/res/drawable-xxhdpi/fplib_ic_xml_file.png rename to library/src/main/res/drawable-xxhdpi/fplib_ic_xml_file.png diff --git a/library/src/main/res/drawable-xxhdpi/ic_plus.png b/library/src/main/res/drawable-xxhdpi/ic_plus.png new file mode 100644 index 0000000..6454b9f Binary files /dev/null and b/library/src/main/res/drawable-xxhdpi/ic_plus.png differ diff --git a/library/src/main/res/drawable-xxxhdpi/ic_plus.png b/library/src/main/res/drawable-xxxhdpi/ic_plus.png new file mode 100644 index 0000000..f6c335d Binary files /dev/null and b/library/src/main/res/drawable-xxxhdpi/ic_plus.png differ diff --git a/library/src/main/res/drawable/fplib_card.xml b/library/src/main/res/drawable/fplib_card.xml new file mode 100644 index 0000000..3021511 --- /dev/null +++ b/library/src/main/res/drawable/fplib_card.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FPlib/src/main/res/drawable/fplib_circle.xml b/library/src/main/res/drawable/fplib_circle.xml similarity index 86% rename from FPlib/src/main/res/drawable/fplib_circle.xml rename to library/src/main/res/drawable/fplib_circle.xml index f2ac195..9cbfa56 100644 --- a/FPlib/src/main/res/drawable/fplib_circle.xml +++ b/library/src/main/res/drawable/fplib_circle.xml @@ -1,7 +1,7 @@ + android:shape="oval"> diff --git a/FPlib/src/main/res/drawable/fplib_rectangle.xml b/library/src/main/res/drawable/fplib_rectangle.xml similarity index 91% rename from FPlib/src/main/res/drawable/fplib_rectangle.xml rename to library/src/main/res/drawable/fplib_rectangle.xml index 4c168f8..8bf8f9e 100644 --- a/FPlib/src/main/res/drawable/fplib_rectangle.xml +++ b/library/src/main/res/drawable/fplib_rectangle.xml @@ -16,7 +16,7 @@ --> - + - + \ No newline at end of file diff --git a/FPlib/src/main/res/layout/file_info_layout.xml b/library/src/main/res/layout/file_info_layout.xml similarity index 78% rename from FPlib/src/main/res/layout/file_info_layout.xml rename to library/src/main/res/layout/file_info_layout.xml index 5015161..8b0fd0c 100644 --- a/FPlib/src/main/res/layout/file_info_layout.xml +++ b/library/src/main/res/layout/file_info_layout.xml @@ -16,21 +16,23 @@ --> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + android:layout_height="wrap_content"/> + + android:layout_height="wrap_content"/> + android:layout_height="wrap_content"/> \ No newline at end of file diff --git a/FPlib/src/main/res/layout/file_list_header_view.xml b/library/src/main/res/layout/file_list_header_view.xml similarity index 78% rename from FPlib/src/main/res/layout/file_list_header_view.xml rename to library/src/main/res/layout/file_list_header_view.xml index f6e218b..a353d0a 100644 --- a/FPlib/src/main/res/layout/file_list_header_view.xml +++ b/library/src/main/res/layout/file_list_header_view.xml @@ -17,11 +17,11 @@ --> + android:layout_width="fill_parent" + android:layout_height="54dp" + android:background="@android:color/background_light" + android:orientation="vertical" + android:padding="16dp"> + android:textSize="16sp"/> \ No newline at end of file diff --git a/FPlib/src/main/res/layout/file_list_item.xml b/library/src/main/res/layout/file_list_item.xml similarity index 80% rename from FPlib/src/main/res/layout/file_list_item.xml rename to library/src/main/res/layout/file_list_item.xml index 2858927..f1eada4 100644 --- a/FPlib/src/main/res/layout/file_list_item.xml +++ b/library/src/main/res/layout/file_list_item.xml @@ -17,10 +17,10 @@ --> + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical" + android:padding="16dp"> + android:layout_marginTop="2dip" + android:layout_toRightOf="@id/file_item_image_view"/> + android:layout_height="24dp" + android:layout_alignParentRight="true" + android:layout_centerVertical="true"/> \ No newline at end of file diff --git a/FPlib/src/main/res/layout/file_picker_activity_layout.xml b/library/src/main/res/layout/file_picker_activity_layout.xml old mode 100755 new mode 100644 similarity index 74% rename from FPlib/src/main/res/layout/file_picker_activity_layout.xml rename to library/src/main/res/layout/file_picker_activity_layout.xml index 522053f..f66b8bf --- a/FPlib/src/main/res/layout/file_picker_activity_layout.xml +++ b/library/src/main/res/layout/file_picker_activity_layout.xml @@ -16,23 +16,23 @@ --> + xmlns:fab="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="Directory Empty" + android:textColor="@android:color/secondary_text_light" + android:textSize="16sp"/> + android:layout_width="match_parent" + android:layout_height="match_parent"> @@ -59,43 +59,43 @@ - + android:layout_below="@id/header_container" + android:animateLayoutChanges="true" + android:choiceMode="singleChoice" + android:divider="@null" + android:dividerHeight="0dip"> + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + @@ -108,28 +108,29 @@