Compare commits
No commits in common. "gh-pages" and "master" have entirely different histories.
|
|
@ -0,0 +1,9 @@
|
|||
build
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
.DS_Store
|
||||
*.iml
|
||||
.idea
|
||||
*.zip
|
||||
local.properties
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "docs-src/themes/hugo-material-docs"]
|
||||
path = docs-src/themes/hugo-material-docs
|
||||
url = https://github.com/digitalcraftsman/hugo-material-docs.git
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
sudo: false
|
||||
|
||||
language: android
|
||||
env:
|
||||
android:
|
||||
components:
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-23.0.2
|
||||
- build-tools-23.0.1
|
||||
- android-23
|
||||
# - sys-img-armeabi-v7a-android-23
|
||||
- extra-android-support
|
||||
- extra-google-m2repository
|
||||
- extra-android-m2repository
|
||||
licenses:
|
||||
- 'android-sdk-license-.+'
|
||||
- 'google-gdk-license-.+'
|
||||
- '.*intel.+'
|
||||
|
||||
before_cache:
|
||||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.gradle/caches/
|
||||
- $HOME/.gradle/wrapper/
|
||||
|
||||
# Emulator Management: Create, Start and Wait
|
||||
#before_script:
|
||||
# x86 requires kvm which is not available on travis containers
|
||||
# - echo no | android create avd --force -n test -t android-23 --abi armeabi-v7a
|
||||
# - emulator -avd test -gpu off -no-audio -no-window &
|
||||
# - android-wait-for-emulator
|
||||
# - adb shell input keyevent 82 &
|
||||
|
||||
before_install:
|
||||
- chmod +x gradlew
|
||||
|
||||
script:
|
||||
- ./gradlew build check #testDebugUnitTest connectedDebugAndroidTest
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
# Change Log
|
||||
|
||||
## [3.0.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/3.0.0) (2016-07-03)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.3...3.0.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Select one file with a single click [\#92](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/92) ([rastikw](https://github.com/rastikw))
|
||||
- Add ability to enter a new filename [\#83](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/83) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Add ability to input filename [\#82](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/82)
|
||||
|
||||
## [2.5.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.3) (2016-06-09)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.2...2.5.3)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add paths to permission and refresh methods [\#85](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/85)
|
||||
- Add FastScroller sample implementation [\#89](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/89) ([spacecowboy](https://github.com/spacecowboy))
|
||||
- Add a getItem method to FileItemAdapter [\#88](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/88) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Crash while creating folder in dropbox sample [\#76](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/76)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Fast Scroll [\#87](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/87)
|
||||
|
||||
## [2.5.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.2) (2016-02-24)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.1...2.5.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Dropbox should show a progress bar when loading [\#74](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/74)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Dropbox sample can crash due to Inconsistent state in RecyclerView [\#75](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/75)
|
||||
- Dropbox sample crash if multiple press on folder [\#73](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/73)
|
||||
- probebly underscore missing [\#63](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/63)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Update README.md [\#68](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/68) ([callmepeanut](https://github.com/callmepeanut))
|
||||
|
||||
## [2.5.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.1) (2016-01-13)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.0...2.5.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Change license to MPL [\#66](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/66)
|
||||
|
||||
## [2.5.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.0) (2015-11-08)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.4.2...2.5.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add a separator line above OK/Cancel buttons [\#60](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/60)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Hide hidden files in SD card picker by default [\#58](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/58) ([dvrajan](https://github.com/dvrajan))
|
||||
|
||||
## [v2.4.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.4.2) (2015-09-30)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.4.1...v2.4.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- lower minSdk [\#54](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/54)
|
||||
- Spacing of filename items [\#52](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/52)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Lowered minSdk to API 9 [\#55](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/55) ([marbat87](https://github.com/marbat87))
|
||||
- Add Video Thumbnail preview and set default theme to light [\#53](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/53) ([alishari](https://github.com/alishari))
|
||||
|
||||
## [v2.4.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.4.1) (2015-09-14)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.4.0...v2.4.1)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Update to latest build tools and support library 23.0.1 [\#51](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/51) ([alishari](https://github.com/alishari))
|
||||
|
||||
## [v2.4.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.4.0) (2015-08-25)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.3.1...v2.4.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Only allow selecting single files \(when EXTRA\_ALLOW\_MULTIPLE is set to false\) [\#48](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/48)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Make click events overridable [\#49](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/49) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.3.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.3.1) (2015-08-20)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.3.0...v2.3.1)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- FilePicker cannot be used with non-touchscreen devices [\#44](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/44)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Make list focusable. [\#45](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/45) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.3.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.3.0) (2015-08-18)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2.3...v2.3.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Make sure to handle Android M's new permission requests [\#24](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/24)
|
||||
|
||||
## [v2.2.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2.3) (2015-08-04)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2.2...v2.2.3)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Enhancement: Allow adding more arguments to FilePickerFragment [\#40](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/40)
|
||||
- Do not override existing arguments [\#41](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/41) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Update travis config to run on faster containers [\#42](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/42) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.2.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2.2) (2015-08-03)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2.1...v2.2.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Dropbox Sync API is deprecated [\#35](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/35)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Ensure toasts don't get queued up [\#39](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/39) ([hcoosthuizen](https://github.com/hcoosthuizen))
|
||||
|
||||
## [v2.2.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2.1) (2015-07-17)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2...v2.2.1)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Strange error [\#34](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/34)
|
||||
|
||||
## [v2.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2) (2015-07-13)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.1...v2.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Allow fragment to be used with default action bar [\#32](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/32)
|
||||
- Allow setting of toolbar text colour [\#31](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/31)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Licence [\#29](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/29)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Specifying GPL3 or later [\#30](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/30) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.1) (2015-05-30)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.5...v2.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Make filepicker depend only on EXTRA\_ALLOW\_CREATE\_DIR [\#25](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/25)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Build fails [\#21](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/21)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Mention that start-path is configurable [\#20](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/20) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.0.5](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.5) (2015-05-01)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.4...v2.0.5)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Ic\_launcher conflict with app one [\#16](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/16) ([NitroG42](https://github.com/NitroG42))
|
||||
|
||||
## [v2.0.4](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.4) (2015-04-29)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.3...v2.0.4)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Show miniatures for images [\#10](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/10)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Rotation doesn't work [\#15](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/15)
|
||||
|
||||
## [v2.0.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.3) (2015-04-28)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.2...v2.0.3)
|
||||
|
||||
## [v2.0.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.2) (2015-04-28)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.0...v2.0.2)
|
||||
|
||||
## [v2.0.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.0) (2015-04-27)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.2.0...v2.0.0)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- crash InBackground thread [\#13](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/13)
|
||||
- Crash on root folders [\#12](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/12)
|
||||
|
||||
## [v1.2.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.2.0) (2015-04-27)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1.3...v1.2.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Verify Proguard [\#8](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/8)
|
||||
- Upload the Dropbox sample [\#5](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/5)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Add a Gitter chat badge to README.org [\#11](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/11) ([gitter-badger](https://github.com/gitter-badger))
|
||||
- NPE on empty dir [\#6](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/6) ([arkty](https://github.com/arkty))
|
||||
|
||||
## [v1.1.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1.3) (2014-04-02)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1.2...v1.1.3)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- FilePicker: Handle case if startPath does not exist [\#4](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/4)
|
||||
|
||||
## [v1.1.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1.2) (2014-04-02)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1.1...v1.1.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Upload to Maven Central [\#3](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/3)
|
||||
|
||||
## [v1.1.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1.1) (2014-04-02)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1...v1.1.1)
|
||||
|
||||
## [v1.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1) (2014-04-01)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.0...v1.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add only files option [\#2](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/2)
|
||||
- Make create directory toggleable [\#1](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/1)
|
||||
|
||||
## [v1.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.0) (2014-04-01)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v0.99...v1.0)
|
||||
|
||||
## [v0.99](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v0.99) (2014-03-31)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v0.91...v0.99)
|
||||
|
||||
## [v0.91](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v0.91) (2014-03-31)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v0.9...v0.91)
|
||||
|
||||
## [v0.9](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v0.9) (2014-03-31)
|
||||
|
||||
|
||||
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
||||
|
|
@ -0,0 +1,373 @@
|
|||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
||||
|
|
@ -0,0 +1,212 @@
|
|||
# NoNonsense-FilePicker
|
||||
|
||||
<p>
|
||||
<a href="https://flattr.com/submit/auto?user_id=spacecowboy&url=https%3A%2F%2Fgithub.com%2Fspacecowboy%2FNoNonsense-FilePicker" target="_blank"><img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0"></a>
|
||||
<a href="https://travis-ci.org/spacecowboy/NoNonsense-FilePicker">
|
||||
<img src="https://travis-ci.org/spacecowboy/NoNonsense-FilePicker.svg?branch=master">
|
||||
</a>
|
||||
<a href='https://dependencyci.com/github/spacecowboy/NoNonsense-FilePicker'><img src='https://dependencyci.com/github/spacecowboy/NoNonsense-FilePicker/badge' alt='Dependency Status'/></a>
|
||||
<a href='https://bintray.com/spacecowboy/maven/com.nononsenseapps%3Afilepicker/_latestVersion'><img src='https://api.bintray.com/packages/spacecowboy/maven/com.nononsenseapps%3Afilepicker/images/download.svg'></a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<img src="https://raw.githubusercontent.com/spacecowboy/NoNonsense-FilePicker/master/screenshots/Nexus6-picker-dark.png"
|
||||
width="25%"
|
||||
</img>
|
||||
|
||||
<img src="https://raw.githubusercontent.com/spacecowboy/NoNonsense-FilePicker/master/screenshots/Nexus10-picker-dark.png"
|
||||
width="50%"
|
||||
</img>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<img src="https://raw.githubusercontent.com/spacecowboy/NoNonsense-FilePicker/master/screenshots/Nexus6-picker-light.png"
|
||||
width="25%"
|
||||
</img>
|
||||
|
||||
<img src="https://raw.githubusercontent.com/spacecowboy/NoNonsense-FilePicker/master/screenshots/Nexus10-picker-light.png"
|
||||
width="50%"
|
||||
</img>
|
||||
</p>
|
||||
|
||||
- Extendable for sources other than SD-card (Dropbox, FTP, Drive, etc)
|
||||
- Can select multiple items
|
||||
- Select directories or files, or both
|
||||
- Create new directories in the picker
|
||||
- Material theme with AppCompat
|
||||
|
||||
## Yet another file picker library?
|
||||
|
||||
I needed a file picker that had two primary properties:
|
||||
|
||||
1. Easy to extend: I needed a file picker that would work for normal
|
||||
files on the SD-card, and also for using the Dropbox API.
|
||||
2. Able to create a directory in the picker.
|
||||
|
||||
This project has both of those qualities. As a bonus, it also scales
|
||||
nicely to work on any phone or tablet. The core is placed in abstract
|
||||
classes, so it is fairly easy to extend the picker to create
|
||||
your own.
|
||||
|
||||
The library includes an implementation that allows the user to pick
|
||||
files from the SD-card. But the picker could easily be extended to get
|
||||
its file listings from another source, such as Dropbox, FTP, SSH and
|
||||
so on. The sample app includes implementations which browses your
|
||||
Dropbox and a Linux mirror FTP-server.
|
||||
|
||||
By inheriting from an Activity, the picker is able to be rendered as
|
||||
full screen on small screens and as a dialog on large screens. It does
|
||||
this through the theme system, so it is very important for the
|
||||
activity to use a correctly configured theme.
|
||||
|
||||
## How to include in your project (with Gradle)
|
||||
|
||||
Just add the dependency to your *build.gradle*:
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.nononsenseapps:filepicker:3.0.0'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## How to use the included SD-card picker:
|
||||
|
||||
### Include permission in your manifest
|
||||
|
||||
```xml
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
```
|
||||
|
||||
### Include the file picker activity
|
||||
|
||||
The intent filter is optional depending on your use case. Note that
|
||||
the theme set in the manifest is important.
|
||||
|
||||
```xml
|
||||
<activity
|
||||
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/FilePickerTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.GET_CONTENT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
```
|
||||
|
||||
### Configure the theme
|
||||
|
||||
You must **set the theme** on the activity, but you can configure it to
|
||||
match your existing application theme. You can also name it whatever
|
||||
you like..
|
||||
|
||||
```xml
|
||||
<!-- You can also inherit from NNF_BaseTheme.Light -->
|
||||
<style name="FilePickerTheme" parent="NNF_BaseTheme">
|
||||
<!-- Set these to match your theme -->
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
|
||||
<!-- Setting a divider is entirely optional -->
|
||||
<item name="nnf_list_item_divider">?android:attr/listDivider</item>
|
||||
|
||||
<!-- Need to set this also to style create folder dialog -->
|
||||
<item name="alertDialogTheme">@style/FilePickerAlertDialogTheme</item>
|
||||
|
||||
<!-- If you want to set a specific toolbar theme, do it here -->
|
||||
<!-- <item name="nnf_toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item> -->
|
||||
</style>
|
||||
|
||||
<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
</style>
|
||||
```
|
||||
|
||||
### Starting the picker in your app
|
||||
|
||||
```java
|
||||
// This always works
|
||||
Intent i = new Intent(context, FilePickerActivity.class);
|
||||
// This works if you defined the intent filter
|
||||
// Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
|
||||
// Set these depending on your use case. These are the defaults.
|
||||
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
|
||||
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
|
||||
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
|
||||
|
||||
// Configure initial directory by specifying a String.
|
||||
// You could specify a String like "/storage/emulated/0/", but that can
|
||||
// dangerous. Always use Android's API calls to get paths to the SD-card or
|
||||
// internal memory.
|
||||
i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());
|
||||
|
||||
startActivityForResult(i, FILE_CODE);
|
||||
```
|
||||
|
||||
### Handling the result
|
||||
|
||||
If you have a minimum requirement of Jelly Bean (API 16) and above,
|
||||
you can skip the second method.
|
||||
|
||||
```java
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == FILE_CODE && resultCode == Activity.RESULT_OK) {
|
||||
if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
|
||||
// For JellyBean and above
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
ClipData clip = data.getClipData();
|
||||
|
||||
if (clip != null) {
|
||||
for (int i = 0; i < clip.getItemCount(); i++) {
|
||||
Uri uri = clip.getItemAt(i).getUri();
|
||||
// Do something with the URI
|
||||
}
|
||||
}
|
||||
// For Ice Cream Sandwich
|
||||
} else {
|
||||
ArrayList<String> paths = data.getStringArrayListExtra
|
||||
(FilePickerActivity.EXTRA_PATHS);
|
||||
|
||||
if (paths != null) {
|
||||
for (String path: paths) {
|
||||
Uri uri = Uri.parse(path);
|
||||
// Do something with the URI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Uri uri = data.getData();
|
||||
// Do something with the URI
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Want to customize further?
|
||||
|
||||
See some examples in the [Wiki](http://spacecowboy.github.io/NoNonsense-FilePicker/)
|
||||
|
||||
See the sample project for examples on dark and light themes, and
|
||||
implementations using Dropbox and FTP.
|
||||
|
||||
## Not using Gradle yet?
|
||||
|
||||
Time to start! To convert your current Eclipse project, have a look at
|
||||
my brief explanation:
|
||||
<http://cowboyprogrammer.org/convert-to-android-studio-and-gradle-today/>
|
||||
|
||||
## Changelog
|
||||
|
||||
See [CHANGELOG](https://github.com/spacecowboy/NoNonsense-FilePicker/blob/master/CHANGELOG.md)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
public
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
.PHONY: help build server server-with-drafts clean all hugo
|
||||
|
||||
examples_src := $(wildcard content/example/*.md)
|
||||
examples := $(patsubst content/example/%.md,../docs/example/%/index.html,$(examples_src))
|
||||
|
||||
help: ## Print this help text
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||
|
||||
server: ## Build and run a local web server
|
||||
hugo server -d ../docs
|
||||
|
||||
server-with-drafts: ## Run hugo server and include drafts
|
||||
hugo server -D -d ../docs
|
||||
|
||||
clean: ## Clean /docs
|
||||
rm -rf ../docs
|
||||
|
||||
hugo: $(examples) ## Build the site and place output in ../docs
|
||||
all: $(examples)
|
||||
|
||||
print: $(examples)
|
||||
echo $?
|
||||
|
||||
../docs/index.html: content/index.md
|
||||
hugo -d ../docs
|
||||
|
||||
../docs/%/index.html: content/%/index.md
|
||||
hugo -d ../docs
|
||||
|
||||
../docs/example/%/index.html: content/example/%.md
|
||||
hugo -d ../docs
|
||||
|
||||
# Catch all is static content
|
||||
../docs/%: static/%
|
||||
hugo -d ../docs
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
+++
|
||||
[menu.main]
|
||||
parent = "Examples"
|
||||
url = "example/"
|
||||
identifier = ""
|
||||
weight = 99
|
||||
+++
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
baseurl = "http://spacecowboy.github.io/NoNonsense-FilePicker/"
|
||||
languageCode = "en-us"
|
||||
title = "NoNonsense FilePicker"
|
||||
theme = "hugo-material-docs"
|
||||
metadataformat = "toml"
|
||||
canonifyurls = true
|
||||
PygmentsCodeFences = true
|
||||
PygmentsStyle = "friendly"
|
||||
PygmentsOptions = ""
|
||||
#pygmentsuseclasses = true # Will use css file in /static/
|
||||
# Enable Google Analytics by entering your tracking id
|
||||
#googleAnalytics = ""
|
||||
|
||||
[params]
|
||||
# General information
|
||||
author = "SpaceCowboy"
|
||||
description = "An extensible and flexible file-picker for Android."
|
||||
copyright = "Released under the Mozilla Public License 2.0"
|
||||
|
||||
# Repository
|
||||
provider = "GitHub"
|
||||
repo_url = "https://github.com/spacecowboy/NoNonsense-FilePicker"
|
||||
|
||||
version = ""
|
||||
logo = ""
|
||||
favicon = ""
|
||||
|
||||
permalink = "#"
|
||||
|
||||
# Custom assets
|
||||
custom_css = []
|
||||
custom_js = []
|
||||
|
||||
# Syntax highlighting theme
|
||||
highlight_css = ""
|
||||
|
||||
[params.palette]
|
||||
primary = "red"
|
||||
accent = "light green"
|
||||
|
||||
[params.font]
|
||||
text = "Roboto"
|
||||
code = "Roboto Mono"
|
||||
|
||||
|
||||
[social]
|
||||
twitter = ""
|
||||
github = "spacecowboy"
|
||||
|
||||
|
||||
[[menu.main]]
|
||||
name = "Readme"
|
||||
url = "readme/"
|
||||
weight = 0
|
||||
|
||||
[[menu.main]]
|
||||
name = "Changelog"
|
||||
url = "changelog/"
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
name = "License"
|
||||
url = "license/"
|
||||
weight = 20
|
||||
|
||||
[[menu.main]]
|
||||
name = "Examples"
|
||||
weight = 30
|
||||
|
||||
[blackfriday]
|
||||
smartypants = true
|
||||
fractions = true
|
||||
smartDashes = true
|
||||
latexDashes = true
|
||||
plainIDAnchors = true
|
||||
|
|
@ -0,0 +1,263 @@
|
|||
+++
|
||||
date = "2016-07-16T17:06:45+02:00"
|
||||
title = "ChangeLog"
|
||||
|
||||
+++
|
||||
|
||||
## [3.0.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/3.0.0) (2016-07-03)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.3...3.0.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Select one file with a single click [\#92](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/92) ([rastikw](https://github.com/rastikw))
|
||||
- Add ability to enter a new filename [\#83](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/83) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Add ability to input filename [\#82](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/82)
|
||||
|
||||
## [2.5.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.3) (2016-06-09)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.2...2.5.3)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add paths to permission and refresh methods [\#85](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/85)
|
||||
- Add FastScroller sample implementation [\#89](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/89) ([spacecowboy](https://github.com/spacecowboy))
|
||||
- Add a getItem method to FileItemAdapter [\#88](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/88) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Crash while creating folder in dropbox sample [\#76](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/76)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Fast Scroll [\#87](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/87)
|
||||
|
||||
## [2.5.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.2) (2016-02-24)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.1...2.5.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Dropbox should show a progress bar when loading [\#74](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/74)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Dropbox sample can crash due to Inconsistent state in RecyclerView [\#75](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/75)
|
||||
- Dropbox sample crash if multiple press on folder [\#73](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/73)
|
||||
- probebly underscore missing [\#63](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/63)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Update README.md [\#68](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/68) ([callmepeanut](https://github.com/callmepeanut))
|
||||
|
||||
## [2.5.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.1) (2016-01-13)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/2.5.0...2.5.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Change license to MPL [\#66](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/66)
|
||||
|
||||
## [2.5.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/2.5.0) (2015-11-08)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.4.2...2.5.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add a separator line above OK/Cancel buttons [\#60](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/60)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Hide hidden files in SD card picker by default [\#58](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/58) ([dvrajan](https://github.com/dvrajan))
|
||||
|
||||
## [v2.4.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.4.2) (2015-09-30)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.4.1...v2.4.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- lower minSdk [\#54](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/54)
|
||||
- Spacing of filename items [\#52](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/52)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Lowered minSdk to API 9 [\#55](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/55) ([marbat87](https://github.com/marbat87))
|
||||
- Add Video Thumbnail preview and set default theme to light [\#53](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/53) ([alishari](https://github.com/alishari))
|
||||
|
||||
## [v2.4.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.4.1) (2015-09-14)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.4.0...v2.4.1)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Update to latest build tools and support library 23.0.1 [\#51](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/51) ([alishari](https://github.com/alishari))
|
||||
|
||||
## [v2.4.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.4.0) (2015-08-25)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.3.1...v2.4.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Only allow selecting single files \(when EXTRA\_ALLOW\_MULTIPLE is set to false\) [\#48](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/48)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Make click events overridable [\#49](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/49) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.3.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.3.1) (2015-08-20)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.3.0...v2.3.1)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- FilePicker cannot be used with non-touchscreen devices [\#44](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/44)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Make list focusable. [\#45](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/45) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.3.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.3.0) (2015-08-18)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2.3...v2.3.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Make sure to handle Android M's new permission requests [\#24](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/24)
|
||||
|
||||
## [v2.2.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2.3) (2015-08-04)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2.2...v2.2.3)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Enhancement: Allow adding more arguments to FilePickerFragment [\#40](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/40)
|
||||
- Do not override existing arguments [\#41](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/41) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Update travis config to run on faster containers [\#42](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/42) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.2.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2.2) (2015-08-03)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2.1...v2.2.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Dropbox Sync API is deprecated [\#35](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/35)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Ensure toasts don't get queued up [\#39](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/39) ([hcoosthuizen](https://github.com/hcoosthuizen))
|
||||
|
||||
## [v2.2.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2.1) (2015-07-17)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.2...v2.2.1)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Strange error [\#34](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/34)
|
||||
|
||||
## [v2.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.2) (2015-07-13)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.1...v2.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Allow fragment to be used with default action bar [\#32](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/32)
|
||||
- Allow setting of toolbar text colour [\#31](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/31)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Licence [\#29](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/29)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Specifying GPL3 or later [\#30](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/30) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.1) (2015-05-30)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.5...v2.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Make filepicker depend only on EXTRA\_ALLOW\_CREATE\_DIR [\#25](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/25)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Build fails [\#21](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/21)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Mention that start-path is configurable [\#20](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/20) ([spacecowboy](https://github.com/spacecowboy))
|
||||
|
||||
## [v2.0.5](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.5) (2015-05-01)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.4...v2.0.5)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Ic\_launcher conflict with app one [\#16](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/16) ([NitroG42](https://github.com/NitroG42))
|
||||
|
||||
## [v2.0.4](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.4) (2015-04-29)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.3...v2.0.4)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Show miniatures for images [\#10](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/10)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Rotation doesn't work [\#15](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/15)
|
||||
|
||||
## [v2.0.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.3) (2015-04-28)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.2...v2.0.3)
|
||||
|
||||
## [v2.0.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.2) (2015-04-28)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v2.0.0...v2.0.2)
|
||||
|
||||
## [v2.0.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v2.0.0) (2015-04-27)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.2.0...v2.0.0)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- crash InBackground thread [\#13](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/13)
|
||||
- Crash on root folders [\#12](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/12)
|
||||
|
||||
## [v1.2.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.2.0) (2015-04-27)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1.3...v1.2.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Verify Proguard [\#8](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/8)
|
||||
- Upload the Dropbox sample [\#5](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/5)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Add a Gitter chat badge to README.org [\#11](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/11) ([gitter-badger](https://github.com/gitter-badger))
|
||||
- NPE on empty dir [\#6](https://github.com/spacecowboy/NoNonsense-FilePicker/pull/6) ([arkty](https://github.com/arkty))
|
||||
|
||||
## [v1.1.3](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1.3) (2014-04-02)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1.2...v1.1.3)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- FilePicker: Handle case if startPath does not exist [\#4](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/4)
|
||||
|
||||
## [v1.1.2](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1.2) (2014-04-02)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1.1...v1.1.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Upload to Maven Central [\#3](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/3)
|
||||
|
||||
## [v1.1.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1.1) (2014-04-02)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.1...v1.1.1)
|
||||
|
||||
## [v1.1](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.1) (2014-04-01)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v1.0...v1.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add only files option [\#2](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/2)
|
||||
- Make create directory toggleable [\#1](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/1)
|
||||
|
||||
## [v1.0](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v1.0) (2014-04-01)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v0.99...v1.0)
|
||||
|
||||
## [v0.99](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v0.99) (2014-03-31)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v0.91...v0.99)
|
||||
|
||||
## [v0.91](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v0.91) (2014-03-31)
|
||||
[Full Changelog](https://github.com/spacecowboy/NoNonsense-FilePicker/compare/v0.9...v0.91)
|
||||
|
||||
## [v0.9](https://github.com/spacecowboy/NoNonsense-FilePicker/tree/v0.9) (2014-03-31)
|
||||
|
||||
|
||||
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
+++
|
||||
date = "2016-07-16T17:21:28+02:00"
|
||||
title = "Custom item layout"
|
||||
|
||||
[menu]
|
||||
[menu.main]
|
||||
identifier = "custom_item_layout"
|
||||
url = "example/custom_item_layout/"
|
||||
parent = "Examples"
|
||||
weight = 20
|
||||
|
||||
+++
|
||||
|
||||
Say you want to browse some files which have really long names. By default, filenames will be cut if they exceed one line in width like `ThisIsAReallyLongFi...`. What if we really wanted it show like in this image?
|
||||
|
||||

|
||||
|
||||
The behavior of the text is defined in the listitem layouts:
|
||||
[nnf_filepicker_listitem_checkable](https://github.com/spacecowboy/NoNonsense-FilePicker/blob/master/library/src/main/res/layout/nnf_filepicker_listitem_checkable.xml)
|
||||
and
|
||||
[nnf_filepicker_listitem_dir](https://github.com/spacecowboy/NoNonsense-FilePicker/blob/master/library/src/main/res/layout/nnf_filepicker_listitem_dir.xml).
|
||||
|
||||
There are two kinds of layouts, one with a checkbox to allow selection, and one without a checkbox. The second one is also used for the special header item `..` though you could of course have a special layout for that if you wanted.
|
||||
|
||||
### Layouts
|
||||
|
||||
Let's create some new layouts which will support longer filenames as follows:
|
||||
|
||||
**longer_listitem_checkable.xml**
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:minHeight="?android:listPreferredItemHeight"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
<!--suppress AndroidDomInspection -->
|
||||
<ImageView
|
||||
android:id="@+id/item_icon"
|
||||
android:layout_width="?android:listPreferredItemHeight"
|
||||
android:layout_height="?android:listPreferredItemHeight"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/nnf_ic_file_folder"
|
||||
android:tint="?attr/colorAccent"
|
||||
android:visibility="visible"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/text1"
|
||||
style="?android:textAppearanceLarge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:listPreferredItemHeight"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="4"
|
||||
android:padding="8dp"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingRight="8dp"
|
||||
tools:ignore="RtlSymmetry" />
|
||||
|
||||
</LinearLayout>
|
||||
```
|
||||
|
||||
**longer_listitem_dir.xml**
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:minHeight="?android:listPreferredItemHeight"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<!--suppress AndroidDomInspection -->
|
||||
<ImageView
|
||||
android:id="@+id/item_icon"
|
||||
android:layout_width="?android:listPreferredItemHeight"
|
||||
android:layout_height="?android:listPreferredItemHeight"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/nnf_ic_file_folder"
|
||||
android:tint="?attr/colorAccent"
|
||||
android:visibility="visible"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/text1"
|
||||
style="?android:textAppearanceLarge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:listPreferredItemHeight"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="4"
|
||||
android:padding="8dp"/>
|
||||
</LinearLayout>
|
||||
```
|
||||
|
||||
Note that I defined the TextViews to have a maximum of 4 lines (actual number is up to you), and a minimum height of `android:listPreferredItemHeight` (this I recommend, otherwise it looks wonky and off-center). And just be clear, the *ids* of these fields must be `@+id/item_icon`, `@android:id/text1`, and `@+id/checkbox`, or the code WILL crash on you.
|
||||
|
||||
### Code
|
||||
|
||||
To use the new layouts, you need to override the `onCreateViewHolder` method in
|
||||
[AbstractFilePickerFragment](https://github.com/spacecowboy/NoNonsense-FilePicker/blob/master/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java).
|
||||
|
||||
Since this example will be browsing the SD-card, I will extend from the built-in FilePickerFragment.
|
||||
|
||||
```java
|
||||
public class CustomLayoutFilePickerFragment extends FilePickerFragment {
|
||||
/**
|
||||
* @param parent Containing view
|
||||
* @param viewType which the ViewHolder will contain. Will be one of:
|
||||
* [VIEWTYPE_HEADER, VIEWTYPE_CHECKABLE, VIEWTYPE_DIR]. It is OK, and even expected, to use the same
|
||||
* layout for VIEWTYPE_HEADER and VIEWTYPE_DIR.
|
||||
* @return a view holder for a file or directory (the difference is presence of checkbox).
|
||||
*/
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v;
|
||||
switch (viewType) {
|
||||
case LogicHandler.VIEWTYPE_HEADER:
|
||||
v = LayoutInflater.from(getActivity()).inflate(R.layout.longer_listitem_dir,
|
||||
parent, false);
|
||||
return new HeaderViewHolder(v);
|
||||
case LogicHandler.VIEWTYPE_CHECKABLE:
|
||||
v = LayoutInflater.from(getActivity()).inflate(R.layout.longer_listitem_checkable,
|
||||
parent, false);
|
||||
return new CheckableViewHolder(v);
|
||||
case LogicHandler.VIEWTYPE_DIR:
|
||||
default:
|
||||
v = LayoutInflater.from(getActivity()).inflate(R.layout.longer_listitem_dir,
|
||||
parent, false);
|
||||
return new DirViewHolder(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
And as always, to use your custom fragment you need a custom activity which loads it for you:
|
||||
|
||||
```java
|
||||
public class CustomLayoutPickerActivity extends AbstractFilePickerActivity {
|
||||
|
||||
public CustomLayoutPickerActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractFilePickerFragment<File> getFragment(
|
||||
final String startPath, final int mode, final boolean allowMultiple,
|
||||
final boolean allowCreateDir) {
|
||||
// Load our custom fragment here
|
||||
AbstractFilePickerFragment<File> fragment = new CustomLayoutFilePickerFragment();
|
||||
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
|
||||
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
|
||||
mode, allowMultiple, allowCreateDir);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
+++
|
||||
date = "2016-07-16T17:32:07+02:00"
|
||||
title = "Filter based on file extension"
|
||||
|
||||
[menu]
|
||||
[menu.main]
|
||||
identifier = "filter_file_extension"
|
||||
url = "example/filter_file_extension/"
|
||||
parent = "Examples"
|
||||
weight = 10
|
||||
|
||||
+++
|
||||
|
||||
|
||||
By default, the SD-card picker will display all files in alphabetical order. But let's say that your app can only handle a specific type of file, like `.txt`-files. Here's a minimal example which will only display such files.
|
||||
|
||||
First, a convenience method to get the extension of files:
|
||||
|
||||
```java
|
||||
// File extension to filter on, including the initial dot.
|
||||
private static final String EXTENSION = ".txt";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @return The file extension. If file has no extension, it returns null.
|
||||
*/
|
||||
private String getExtension(@NonNull File file) {
|
||||
String path = file.getPath();
|
||||
int i = path.lastIndexOf(".");
|
||||
if (i < 0) {
|
||||
return null;
|
||||
} else {
|
||||
return path.substring(i);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The decision to display files or not is done with the `isItemVisible` method. Just add a check for the file-extension:
|
||||
|
||||
```java
|
||||
@Override
|
||||
protected boolean isItemVisible(final File file) {
|
||||
// simplified behavior (see below full code)
|
||||
// return isDir(file) || (mode == MODE_FILE || mode == MODE_FILE_AND_DIR);
|
||||
if (!isDir(file) && (mode == MODE_FILE || mode == MODE_FILE_AND_DIR)) {
|
||||
String ext = getExtension(file);
|
||||
return ext != null && EXTENSION.equalsIgnoreCase(ext);
|
||||
}
|
||||
return isDir(file);
|
||||
}
|
||||
```
|
||||
|
||||
### Before and After
|
||||
<img src="/screenshots/filter_before.png" width="30%" alt="Before"/>
|
||||
<img src="/screenshots/filter_after.png" width="30%" alt="After"/>
|
||||
|
||||
### Full Fragment code
|
||||
|
||||
```java
|
||||
import com.nononsenseapps.filepicker.FilePickerFragment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FilteredFilePickerFragment extends FilePickerFragment {
|
||||
|
||||
// File extension to filter on
|
||||
private static final String EXTENSION = ".txt";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @return The file extension. If file has no extension, it returns null.
|
||||
*/
|
||||
private String getExtension(@NonNull File file) {
|
||||
String path = file.getPath();
|
||||
int i = path.lastIndexOf(".");
|
||||
if (i < 0) {
|
||||
return null;
|
||||
} else {
|
||||
return path.substring(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isItemVisible(final File file) {
|
||||
boolean ret = super.isItemVisible(file);
|
||||
if (ret && !isDir(file) && (mode == MODE_FILE || mode == MODE_FILE_AND_DIR)) {
|
||||
String ext = getExtension(file);
|
||||
return ext != null && EXTENSION.equalsIgnoreCase(ext);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
+++
|
||||
date = "2016-07-16T17:33:43+02:00"
|
||||
title = "Override the back button"
|
||||
|
||||
[menu]
|
||||
[menu.main]
|
||||
identifier = "override_back_button"
|
||||
url = "example/override_back_button/"
|
||||
parent = "Examples"
|
||||
weight = 70
|
||||
|
||||
+++
|
||||
|
||||
In case you want the back button to navigate the hierarchy instead of
|
||||
instantly exiting the activity, this is one approach you might take.
|
||||
|
||||
## Create an activity which overrides the back button and loads a custom fragment
|
||||
|
||||
```java
|
||||
package com.nononsenseapps.filepicker.examples.backbutton;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import com.nononsenseapps.filepicker.AbstractFilePickerFragment;
|
||||
import com.nononsenseapps.filepicker.FilePickerActivity;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BackHandlingFilePickerActivity extends FilePickerActivity {
|
||||
|
||||
/**
|
||||
* Need access to the fragment
|
||||
*/
|
||||
BackHandlingFilePickerFragment currentFragment;
|
||||
|
||||
/**
|
||||
* Return a copy of the new fragment and set the variable above.
|
||||
*/
|
||||
@Override
|
||||
protected AbstractFilePickerFragment<File> getFragment(
|
||||
final String startPath, final int mode, final boolean allowMultiple,
|
||||
final boolean allowDirCreate, final boolean allowExistingFile,
|
||||
final boolean singleClick) {
|
||||
|
||||
// startPath is allowed to be null.
|
||||
// In that case, default folder should be SD-card and not "/"
|
||||
String path = (startPath != null ? startPath
|
||||
: Environment.getExternalStorageDirectory().getPath());
|
||||
|
||||
currentFragment = new BackHandlingFilePickerFragment();
|
||||
currentFragment.setArgs(path, mode, allowMultiple, allowDirCreate,
|
||||
allowExistingFile, singleClick);
|
||||
return currentFragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the back-button.
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// If at top most level, normal behaviour
|
||||
if (currentFragment.isBackTop()) {
|
||||
super.onBackPressed();
|
||||
} else {
|
||||
// Else go up
|
||||
currentFragment.goUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## In your custom fragment, implement the goUp and isBackTop methods
|
||||
|
||||
```java
|
||||
package com.nononsenseapps.filepicker.examples.backbutton;
|
||||
|
||||
import com.nononsenseapps.filepicker.FilePickerFragment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BackHandlingFilePickerFragment extends FilePickerFragment {
|
||||
|
||||
/**
|
||||
* For consistency, the top level the back button checks against should be the start path.
|
||||
* But it will fall back on /.
|
||||
*/
|
||||
public File getBackTop() {
|
||||
return getPath(getArguments().getString(KEY_START_PATH, "/"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the current path is the startpath or /
|
||||
*/
|
||||
public boolean isBackTop() {
|
||||
return 0 == compareFiles(mCurrentPath, getBackTop()) ||
|
||||
0 == compareFiles(mCurrentPath, new File("/"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Go up on level, same as pressing on "..".
|
||||
*/
|
||||
public void goUp() {
|
||||
mCurrentPath = getParent(mCurrentPath);
|
||||
mCheckedItems.clear();
|
||||
mCheckedVisibleViewHolders.clear();
|
||||
refresh(mCurrentPath);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Example manifest
|
||||
|
||||
Make sure `android-theme` points to the correct theme.
|
||||
|
||||
```xml
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.nononsenseapps.filepicker.examples">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<!-- Only needed to create sub directories. -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/FilePickerTheme">
|
||||
|
||||
<activity
|
||||
android:name=".backbutton.BackHandlingFilePickerActivity"
|
||||
android:label="Override back button"
|
||||
android:theme="@style/FilePickerTheme">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
```
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
+++
|
||||
date = "2016-07-16T17:35:01+02:00"
|
||||
title = "Override selection behavior"
|
||||
|
||||
[menu]
|
||||
[menu.main]
|
||||
identifier = "override_selection_behavior"
|
||||
url = "example/override_selection_behavior/"
|
||||
parent = "Examples"
|
||||
weight = 99
|
||||
|
||||
+++
|
||||
|
||||
New in [2.4.0](https://github.com/spacecowboy/NoNonsense-FilePicker/releases/tag/v2.4.0) are overridable methods to handle UI-interactions. The following methods are now available for augmentation:
|
||||
|
||||
- onClickOK, handles ok button.
|
||||
- onClickCancel, handles cancel button.
|
||||
- onClickHeader, handles clicks on "..".
|
||||
- onClickDir, handles clicks on non-selectable items (usually directories).
|
||||
- onLongClickDir, handles long clicks on non-selectable items.
|
||||
- onClickCheckable, handles clicks on selectable items.
|
||||
- onLongClickCheckable, handles long clicks on selectable items.
|
||||
- onClickCheckBox, handles clicks on the checkbox of selectable items.
|
||||
|
||||
Please see the existing implementations before you override any of them.
|
||||
|
||||
## Simple example, make clicks instantly select items
|
||||
|
||||
As asked in [#48](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/48), what if the picker is configured for selecting a single file and you want a click on that to instantly return the result. The default implementation will mark the item as selected, and then the user is required to press the OK button. This small change will make the operation a single click action, returning instantly once the user selects something.
|
||||
|
||||
```java
|
||||
public class SingleFilePickerFragment extends FilePickerFragment {
|
||||
@Override
|
||||
public void onClickCheckable(View v, CheckableViewHolder vh) {
|
||||
if (!allowMultiple) {
|
||||
// Clear is necessary, in case user clicked some checkbox directly
|
||||
mCheckedItems.clear();
|
||||
mCheckedItems.add(vh.file);
|
||||
onClickOk(null);
|
||||
} else {
|
||||
super.onClickCheckable(v, vh);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now the astute reader might wonder, if my filepicker is only going to be used for selecting single files, why not just do:
|
||||
|
||||
```java
|
||||
public void onClickCheckable(View v, CheckableViewHolder vh) {
|
||||
super.onClickCheckable(v, vh);
|
||||
onClickOk(null);
|
||||
}
|
||||
```
|
||||
|
||||
The reason is that the default implementation will animate the checkbox being selected on press. If you are closing the picker directly once the user selects something, you are basically animating something which isn't going to be seen and thus you are wasting (not that much) resources. Better to not animate at all in that case.
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
+++
|
||||
date = "2016-07-16T17:10:46+02:00"
|
||||
title = "Change the sort order"
|
||||
|
||||
[menu]
|
||||
[menu.main]
|
||||
parent = "Examples"
|
||||
identifier = "sortorder"
|
||||
url = "example/sortorder/"
|
||||
weight = 0
|
||||
+++
|
||||
|
||||
By default, the SD-card picker will display all files in alphabetical order. But what if you want a different sort-order?
|
||||
|
||||
You can override the sorting by overriding the `compareFiles`-method:
|
||||
|
||||
```java
|
||||
@Override
|
||||
protected int compareFiles(File lhs, File rhs) {
|
||||
if (lhs.isDirectory() && !rhs.isDirectory()) {
|
||||
return -1;
|
||||
} else if (rhs.isDirectory() && !lhs.isDirectory()) {
|
||||
return 1;
|
||||
}
|
||||
// This was the previous behaviour for all file-file comparisons. Now it's
|
||||
// only done if the files have the same extension, or no extension.
|
||||
else if (getExtension(lhs) != null && getExtension(lhs).equalsIgnoreCase(getExtension(rhs)) ||
|
||||
getExtension(lhs) == null && getExtension(rhs) == null) {
|
||||
return lhs.getName().compareToIgnoreCase(rhs.getName());
|
||||
}
|
||||
// Otherwise, we sort on extension placing files with no extension last.
|
||||
else if (getExtension(lhs) != null && getExtension(rhs) != null) {
|
||||
// Both have extension, just compare extensions
|
||||
return getExtension(lhs).compareToIgnoreCase(getExtension(rhs));
|
||||
} else if (getExtension(lhs) != null) {
|
||||
// Left has extension, place it first
|
||||
return -1;
|
||||
} else {
|
||||
// Right has extension, place it first
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Before and After
|
||||
<img src="/screenshots/sorting_before.png" width="30%" alt="Before"/>
|
||||
<img src="/screenshots/sorting_after.png" width="30%" alt="After"/>
|
||||
|
||||
### Full Fragment code
|
||||
|
||||
```java
|
||||
import com.nononsenseapps.filepicker.FilePickerFragment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SortedFilePickerFragment extends FilePickerFragment {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file
|
||||
* @return The file extension. If file has no extension, it returns null.
|
||||
*/
|
||||
private String getExtension(@NonNull File file) {
|
||||
String path = file.getPath();
|
||||
int i = path.lastIndexOf(".");
|
||||
if (i < 0) {
|
||||
return null;
|
||||
} else {
|
||||
return path.substring(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two files to determine their relative sort order. This follows the usual
|
||||
* comparison interface. Override to determine your own custom sort order.
|
||||
*
|
||||
* @param lhs File on the "left-hand side"
|
||||
* @param rhs File on the "right-hand side"
|
||||
* @return -1 if if lhs should be placed before rhs, 0 if they are equal,
|
||||
* and 1 if rhs should be placed before lhs
|
||||
*/
|
||||
@Override
|
||||
protected int compareFiles(File lhs, File rhs) {
|
||||
if (lhs.isDirectory() && !rhs.isDirectory()) {
|
||||
return -1;
|
||||
} else if (rhs.isDirectory() && !lhs.isDirectory()) {
|
||||
return 1;
|
||||
}
|
||||
// This was the previous behaviour for all file-file comparisons. Now it's
|
||||
// only done if the files have the same extension, or no extension.
|
||||
else if (getExtension(lhs) != null && getExtension(lhs).equalsIgnoreCase(getExtension(rhs)) ||
|
||||
getExtension(lhs) == null && getExtension(rhs) == null) {
|
||||
return lhs.getName().compareToIgnoreCase(rhs.getName());
|
||||
}
|
||||
// Otherwise, we sort on extension placing files with no extension last.
|
||||
else if (getExtension(lhs) != null && getExtension(rhs) != null) {
|
||||
// Both have extension, just compare extensions
|
||||
return getExtension(lhs).compareToIgnoreCase(getExtension(rhs));
|
||||
} else if (getExtension(lhs) != null) {
|
||||
// Left has extension, place it first
|
||||
return -1;
|
||||
} else {
|
||||
// Right has extension, place it first
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
+++
|
||||
date = "2016-07-16T17:36:40+02:00"
|
||||
title = "Standalone fragment"
|
||||
|
||||
[menu]
|
||||
[menu.main]
|
||||
identifier = "standalone_fragment"
|
||||
url = "example/standalone_fragment/"
|
||||
parent = "Examples"
|
||||
weight = 99
|
||||
|
||||
+++
|
||||
|
||||
|
||||
To use the fragment together with an existing toolbar/action bar, a few things should be overridden.
|
||||
|
||||
Here's a minimal example where the toolbar is intercepted from being set as the main toolbar. The menu creation is also intercepted and populates the toolbar directly.
|
||||
|
||||
```java
|
||||
public class StandaloneFilePickerFragment extends FilePickerFragment {
|
||||
|
||||
protected Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
protected void setupToolbar(Toolbar toolbar) {
|
||||
// Prevent it from being set as main toolbar by NOT calling super.setupToolbar().
|
||||
mToolbar = toolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// Populate the toolbar with the menu items instead of the action bar.
|
||||
mToolbar.inflateMenu(R.menu.picker_actions);
|
||||
|
||||
// Set a menu listener on the toolbar with calls the regular onOptionsItemSelected method.
|
||||
mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
});
|
||||
|
||||
// This is usually handled in onCreateOptions so do it here instead.
|
||||
MenuItem item = mToolbar.getMenu().findItem(com.nononsenseapps.filepicker.R.id.nnf_action_createdir);
|
||||
item.setVisible(allowCreateDir);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -0,0 +1,220 @@
|
|||
+++
|
||||
date = "2016-07-16T16:42:44+02:00"
|
||||
title = "Readme"
|
||||
type = "index"
|
||||
aliases = ["/readme/"]
|
||||
+++
|
||||
|
||||
<p>
|
||||
<img src="/screenshots/Nexus6-picker-dark.png" width="25%"/>
|
||||
|
||||
<img src="/screenshots/Nexus10-picker-light.png" width="60%"/>
|
||||
</p>
|
||||
|
||||
- Extendable for sources other than SD-card (Dropbox, FTP, Drive, etc)
|
||||
- Can select multiple items
|
||||
- Select directories or files, or both
|
||||
- Create new directories in the picker
|
||||
- Material theme with AppCompat
|
||||
|
||||
## Yet another file picker library?
|
||||
|
||||
I needed a file picker that had two primary properties:
|
||||
|
||||
1. Easy to extend: I needed a file picker that would work for normal
|
||||
files on the SD-card, and also for using the Dropbox API.
|
||||
2. Able to create a directory in the picker.
|
||||
|
||||
This project has both of those qualities. As a bonus, it also scales
|
||||
nicely to work on any phone or tablet. The core is placed in abstract
|
||||
classes, so it is fairly easy to extend the picker to create
|
||||
your own.
|
||||
|
||||
The library includes an implementation that allows the user to pick
|
||||
files from the SD-card. But the picker could easily be extended to get
|
||||
its file listings from another source, such as Dropbox, FTP, SSH and
|
||||
so on. The sample app includes implementations which browses your
|
||||
Dropbox and a Linux mirror FTP-server.
|
||||
|
||||
By inheriting from an Activity, the picker is able to be rendered as
|
||||
full screen on small screens and as a dialog on large screens. It does
|
||||
this through the theme system, so it is very important for the
|
||||
activity to use a correctly configured theme.
|
||||
|
||||
## How to include in your project (with Gradle)
|
||||
|
||||
Just add the dependency to your *build.gradle*:
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.nononsenseapps:filepicker:3.0.0'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## How to use the included SD-card picker:
|
||||
|
||||
### Include permission in your manifest
|
||||
|
||||
```xml
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
```
|
||||
|
||||
### Include the file picker activity
|
||||
|
||||
The intent filter is optional depending on your use case. Note that
|
||||
the theme set in the manifest is important.
|
||||
|
||||
```xml
|
||||
<activity
|
||||
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/FilePickerTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.GET_CONTENT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
```
|
||||
|
||||
### Configure the theme
|
||||
|
||||
You must **set the theme** on the activity, but you can configure it to
|
||||
match your existing application theme. You can also name it whatever
|
||||
you like..
|
||||
|
||||
```xml
|
||||
<!-- You can also inherit from NNF_BaseTheme.Light -->
|
||||
<style name="FilePickerTheme" parent="NNF_BaseTheme">
|
||||
<!-- Set these to match your theme -->
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
|
||||
<!-- Need to set this also to style create folder dialog -->
|
||||
<item name="alertDialogTheme">@style/FilePickerAlertDialogTheme</item>
|
||||
|
||||
<!-- If you want to set a specific toolbar theme, do it here -->
|
||||
<!-- <item name="nnf_toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item> -->
|
||||
</style>
|
||||
|
||||
<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
</style>
|
||||
```
|
||||
|
||||
### Starting the picker in your app
|
||||
|
||||
```java
|
||||
// This always works
|
||||
Intent i = new Intent(context, FilePickerActivity.class);
|
||||
// This works if you defined the intent filter
|
||||
// Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
|
||||
// Set these depending on your use case. These are the defaults.
|
||||
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
|
||||
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
|
||||
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
|
||||
|
||||
// Configure initial directory by specifying a String.
|
||||
// You could specify a String like "/storage/emulated/0/", but that can
|
||||
// dangerous. Always use Android's API calls to get paths to the SD-card or
|
||||
// internal memory.
|
||||
i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());
|
||||
|
||||
startActivityForResult(i, FILE_CODE);
|
||||
```
|
||||
|
||||
### Handling the result
|
||||
|
||||
If you have a minimum requirement of Jelly Bean (API 16) and above,
|
||||
you can skip the second method.
|
||||
|
||||
```java
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == FILE_CODE && resultCode == Activity.RESULT_OK) {
|
||||
if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
|
||||
// For JellyBean and above
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
ClipData clip = data.getClipData();
|
||||
|
||||
if (clip != null) {
|
||||
for (int i = 0; i < clip.getItemCount(); i++) {
|
||||
Uri uri = clip.getItemAt(i).getUri();
|
||||
// Do something with the URI
|
||||
}
|
||||
}
|
||||
// For Ice Cream Sandwich
|
||||
} else {
|
||||
ArrayList<String> paths = data.getStringArrayListExtra
|
||||
(FilePickerActivity.EXTRA_PATHS);
|
||||
|
||||
if (paths != null) {
|
||||
for (String path: paths) {
|
||||
Uri uri = Uri.parse(path);
|
||||
// Do something with the URI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Uri uri = data.getData();
|
||||
// Do something with the URI
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Customizing the picker
|
||||
|
||||
Extend `AbstractFilePickerActivity` and implement `getFragment`. It
|
||||
should return an instance of `AbstractFilePickerFragment`. This
|
||||
basically means that the activity is just the same boilerplate with as
|
||||
single line changed (see the sample app's Dropbox example for an
|
||||
activity which actually has to do some extra work):
|
||||
|
||||
```java
|
||||
// Making a custom SD-card picker
|
||||
public class MyPickerActivity extends AbstractFilePickerActivity<File> {
|
||||
|
||||
public MyPickerActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractFilePickerFragment<File> getFragment(
|
||||
final String startPath, final int mode, final boolean allowMultiple,
|
||||
final boolean allowCreateDir) {
|
||||
// Only the fragment in this line needs to be changed
|
||||
AbstractFilePickerFragment<File> fragment = new MyPickerFragment();
|
||||
fragment.setArgs(startPath, mode, allowMultiple, allowCreateDir);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Extend AbstractFilePickerFragment
|
||||
|
||||
Which requires you to implement
|
||||
|
||||
- onNewFolder
|
||||
- isDir
|
||||
- getParent
|
||||
- getPath
|
||||
- getFullPath
|
||||
- getName
|
||||
- getRoot
|
||||
- toUri
|
||||
- getLoader
|
||||
|
||||
If you only want to make a custom SD-card picker, you can instead extend `FilePickerFragment`, and only override the relevant method you want to change.
|
||||
|
||||
See the sample app and the examples for some concrete code.
|
||||
|
|
@ -0,0 +1,382 @@
|
|||
+++
|
||||
date = "2016-07-16T16:35:07+02:00"
|
||||
title = "License"
|
||||
|
||||
+++
|
||||
Copyright (c) 2016 Jonas Kalderstam <jonas@cowboyprogrammer.org>
|
||||
|
||||
```text
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
||||
```
|
||||
|
After Width: | Height: | Size: 370 KiB |
|
After Width: | Height: | Size: 370 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 1134976b4fcaec84c5862460a85eaf207d8566f8
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>ChangeLog - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>Custom item layout - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -531,14 +532,14 @@ and
|
|||
|
||||
<div class="next">
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/" title="Customizing the filepicker">
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/sortorder/" title="Change the sort order">
|
||||
<span class="direction">
|
||||
Next
|
||||
</span>
|
||||
<div class="page">
|
||||
<div class="stretch">
|
||||
<div class="title">
|
||||
Customizing the filepicker
|
||||
Change the sort order
|
||||
</div>
|
||||
</div>
|
||||
<div class="button button-next" role="button" aria-label="Next">
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>Filter based on file extension - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<title>Customizing the filepicker - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>Examples - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -68,16 +69,14 @@
|
|||
<script src="http://spacecowboy.github.io/NoNonsense-FilePicker/javascripts/modernizr.js"></script>
|
||||
|
||||
|
||||
<link href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/index.xml" rel="alternate" type="application/rss+xml" title="NoNonsense FilePicker" />
|
||||
<link href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/index.xml" rel="feed" type="application/rss+xml" title="NoNonsense FilePicker" />
|
||||
|
||||
|
||||
</head>
|
||||
<body class="palette-primary-red palette-accent-light green">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="backdrop">
|
||||
<div class="backdrop-paper"></div>
|
||||
</div>
|
||||
|
|
@ -96,7 +95,7 @@
|
|||
</div>
|
||||
<div class="stretch">
|
||||
<div class="title">
|
||||
Customizing the filepicker
|
||||
Example
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -135,9 +134,6 @@
|
|||
<div class="name">
|
||||
<strong>NoNonsense FilePicker </strong>
|
||||
|
||||
<br>
|
||||
spacecowboy/NoNonsense-FilePicker
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
|
@ -330,52 +326,63 @@
|
|||
|
||||
<article class="article">
|
||||
<div class="wrapper">
|
||||
<h1>Customizing the filepicker </h1>
|
||||
<h1>Pages in Example</h1>
|
||||
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/standalone_fragment/" title="Standalone fragment">
|
||||
<h2>Standalone fragment</h2>
|
||||
</a>
|
||||
|
||||
<p>Extend <code>AbstractFilePickerActivity</code> and implement <code>getFragment</code>. It
|
||||
should return an instance of <code>AbstractFilePickerFragment</code>. This
|
||||
basically means that the activity is just the same boilerplate with as
|
||||
single line changed (see the sample app’s Dropbox example for an
|
||||
activity which actually has to do some extra work):</p>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #60a0b0; font-style: italic">// Making a custom SD-card picker</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">MyPickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> AbstractFilePickerActivity<span style="color: #666666"><</span>File<span style="color: #666666">></span> <span style="color: #666666">{</span>
|
||||
<br>
|
||||
To use the fragment together with an existing toolbar/action bar, a few things should be overridden. Here’s a minimal example where the toolbar is intercepted from being set as the main toolbar. The menu creation is also intercepted and populates the toolbar directly. public class StandaloneFilePickerFragment extends FilePickerFragment { protected Toolbar mToolbar; @Override protected void setupToolbar(Toolbar toolbar) { // Prevent it from being set as main toolbar by NOT calling super.setupToolbar().
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #06287e">MyPickerActivity</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">super</span><span style="color: #666666">();</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<hr>
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/override_selection_behavior/" title="Override selection behavior">
|
||||
<h2>Override selection behavior</h2>
|
||||
</a>
|
||||
|
||||
<span style="color: #555555; font-weight: bold">@Override</span>
|
||||
<span style="color: #007020; font-weight: bold">protected</span> AbstractFilePickerFragment<span style="color: #666666"><</span>File<span style="color: #666666">></span> <span style="color: #06287e">getFragment</span><span style="color: #666666">(</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> String startPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">int</span> mode<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowMultiple<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowCreateDir<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// Only the fragment in this line needs to be changed</span>
|
||||
AbstractFilePickerFragment<span style="color: #666666"><</span>File<span style="color: #666666">></span> fragment <span style="color: #666666">=</span> <span style="color: #007020; font-weight: bold">new</span> MyPickerFragment<span style="color: #666666">();</span>
|
||||
fragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>startPath<span style="color: #666666">,</span> mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowCreateDir<span style="color: #666666">);</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> fragment<span style="color: #666666">;</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
<br>
|
||||
New in 2.4.0 are overridable methods to handle UI-interactions. The following methods are now available for augmentation: onClickOK, handles ok button. onClickCancel, handles cancel button. onClickHeader, handles clicks on “..”. onClickDir, handles clicks on non-selectable items (usually directories). onLongClickDir, handles long clicks on non-selectable items. onClickCheckable, handles clicks on selectable items. onLongClickCheckable, handles long clicks on selectable items. onClickCheckBox, handles clicks on the checkbox of selectable items. Please see the existing implementations before you override any of them.
|
||||
|
||||
<h3 id="extend-abstractfilepickerfragment">Extend AbstractFilePickerFragment</h3>
|
||||
<hr>
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/override_back_button/" title="Override the back button">
|
||||
<h2>Override the back button</h2>
|
||||
</a>
|
||||
|
||||
<p>Which requires you to implement</p>
|
||||
<br>
|
||||
In case you want the back button to navigate the hierarchy instead of instantly exiting the activity, this is one approach you might take. Create an activity which overrides the back button and loads a custom fragment package com.nononsenseapps.filepicker.examples.backbutton; import android.os.Environment; import com.nononsenseapps.filepicker.AbstractFilePickerFragment; import com.nononsenseapps.filepicker.FilePickerActivity; import java.io.File; public class BackHandlingFilePickerActivity extends FilePickerActivity { /** * Need access to the fragment */ BackHandlingFilePickerFragment currentFragment; /** * Return a copy of the new fragment and set the variable above.
|
||||
|
||||
<ul>
|
||||
<li>onNewFolder</li>
|
||||
<li>isDir</li>
|
||||
<li>getParent</li>
|
||||
<li>getPath</li>
|
||||
<li>getFullPath</li>
|
||||
<li>getName</li>
|
||||
<li>getRoot</li>
|
||||
<li>toUri</li>
|
||||
<li>getLoader</li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/filter_file_extension/" title="Filter based on file extension">
|
||||
<h2>Filter based on file extension</h2>
|
||||
</a>
|
||||
|
||||
<p>If you only want to make a custom SD-card picker, you can instead extend <code>FilePickerFragment</code>, and only override the relevant method you want to change.</p>
|
||||
<br>
|
||||
By default, the SD-card picker will display all files in alphabetical order. But let’s say that your app can only handle a specific type of file, like .txt-files. Here’s a minimal example which will only display such files. First, a convenience method to get the extension of files: // File extension to filter on, including the initial dot. private static final String EXTENSION = ".txt"; /** * * @param file * @return The file extension.
|
||||
|
||||
<hr>
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/custom_item_layout/" title="Custom item layout">
|
||||
<h2>Custom item layout</h2>
|
||||
</a>
|
||||
|
||||
<br>
|
||||
Say you want to browse some files which have really long names. By default, filenames will be cut if they exceed one line in width like ThisIsAReallyLongFi…. What if we really wanted it show like in this image? The behavior of the text is defined in the listitem layouts: nnf_filepicker_listitem_checkable and nnf_filepicker_listitem_dir. There are two kinds of layouts, one with a checkbox to allow selection, and one without a checkbox. The second one is also used for the special header item ..
|
||||
|
||||
<hr>
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/sortorder/" title="Change the sort order">
|
||||
<h2>Change the sort order</h2>
|
||||
</a>
|
||||
|
||||
<br>
|
||||
By default, the SD-card picker will display all files in alphabetical order. But what if you want a different sort-order? You can override the sorting by overriding the compareFiles-method: @Override protected int compareFiles(File lhs, File rhs) { if (lhs.isDirectory() && !rhs.isDirectory()) { return -1; } else if (rhs.isDirectory() && !lhs.isDirectory()) { return 1; } // This was the previous behaviour for all file-file comparisons. Now it's // only done if the files have the same extension, or no extension.
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
<aside class="copyright" role="note">
|
||||
|
||||
|
|
@ -386,57 +393,6 @@ activity which actually has to do some extra work):</p>
|
|||
using the
|
||||
<a href="http://github.com/digitalcraftsman/hugo-material-docs" target="_blank">Material</a> theme.
|
||||
</aside>
|
||||
|
||||
<footer class="footer">
|
||||
|
||||
|
||||
<nav class="pagination" aria-label="Footer">
|
||||
<div class="previous">
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/custom_item_layout/" title="Custom item layout">
|
||||
<span class="direction">
|
||||
Previous
|
||||
</span>
|
||||
<div class="page">
|
||||
<div class="button button-previous" role="button" aria-label="Previous">
|
||||
<i class="icon icon-back"></i>
|
||||
</div>
|
||||
<div class="stretch">
|
||||
<div class="title">
|
||||
Custom item layout
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="next">
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/sortorder/" title="Change the sort order">
|
||||
<span class="direction">
|
||||
Next
|
||||
</span>
|
||||
<div class="page">
|
||||
<div class="stretch">
|
||||
<div class="title">
|
||||
Change the sort order
|
||||
</div>
|
||||
</div>
|
||||
<div class="button button-next" role="button" aria-label="Next">
|
||||
<i class="icon icon-forward"></i>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
|
|
@ -452,8 +408,8 @@ activity which actually has to do some extra work):</p>
|
|||
|
||||
<script>
|
||||
|
||||
var base_url = 'http:\/\/spacecowboy.github.io\/NoNonsense-FilePicker\/';
|
||||
var repo_id = 'spacecowboy\/NoNonsense-FilePicker';
|
||||
var base_url = '';
|
||||
var repo_id = '';
|
||||
|
||||
</script>
|
||||
|
||||
|
|
@ -110,11 +110,20 @@
|
|||
<guid>http://spacecowboy.github.io/NoNonsense-FilePicker/example/override_back_button/</guid>
|
||||
<description>
|
||||
|
||||
<p>In case you want the back button navigate the hierarchy instead of instantly exiting the activity, this
|
||||
is one approach you might take.</p>
|
||||
<p>In case you want the back button to navigate the hierarchy instead of
|
||||
instantly exiting the activity, this is one approach you might take.</p>
|
||||
|
||||
<h2 id="create-an-activity-which-overrides-the-back-button-and-loads-a-custom-fragment">Create an activity which overrides the back button, and loads a custom fragment</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerActivity <span style="color: #666666">{</span>
|
||||
<h2 id="create-an-activity-which-overrides-the-back-button-and-loads-a-custom-fragment">Create an activity which overrides the back button and loads a custom fragment</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #007020; font-weight: bold">package</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.examples.backbutton</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">android.os.Environment</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.AbstractFilePickerFragment</span><span style="color: #666666">;</span>
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.FilePickerActivity</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">java.io.File</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerActivity <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * Need access to the fragment</span>
|
||||
|
|
@ -127,11 +136,17 @@ is one approach you might take.</p>
|
|||
<span style="color: #555555; font-weight: bold">@Override</span>
|
||||
<span style="color: #007020; font-weight: bold">protected</span> AbstractFilePickerFragment<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> <span style="color: #06287e">getFragment</span><span style="color: #666666">(</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> String startPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">int</span> mode<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowMultiple<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowCreateDir<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowDirCreate<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowExistingFile<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> singleClick<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">// startPath is allowed to be null.</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// In that case, default folder should be SD-card and not &quot;/&quot;</span>
|
||||
String path <span style="color: #666666">=</span> <span style="color: #666666">(</span>startPath <span style="color: #666666">!=</span> <span style="color: #007020; font-weight: bold">null</span> <span style="color: #666666">?</span> startPath
|
||||
<span style="color: #666666">:</span> Environment<span style="color: #666666">.</span><span style="color: #4070a0">getExternalStorageDirectory</span><span style="color: #666666">().</span><span style="color: #4070a0">getPath</span><span style="color: #666666">());</span>
|
||||
|
||||
currentFragment <span style="color: #666666">=</span> <span style="color: #007020; font-weight: bold">new</span> BackHandlingFilePickerFragment<span style="color: #666666">();</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// startPath is allowed to be null. In that case, default folder should be SD-card and not &quot;/&quot;</span>
|
||||
currentFragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>startPath <span style="color: #666666">!=</span> <span style="color: #007020; font-weight: bold">null</span> <span style="color: #666666">?</span> startPath <span style="color: #666666">:</span> Environment<span style="color: #666666">.</span><span style="color: #4070a0">getExternalStorageDirectory</span><span style="color: #666666">().</span><span style="color: #4070a0">getPath</span><span style="color: #666666">(),</span>
|
||||
mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowCreateDir<span style="color: #666666">);</span>
|
||||
currentFragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>path<span style="color: #666666">,</span> mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowDirCreate<span style="color: #666666">,</span>
|
||||
allowExistingFile<span style="color: #666666">,</span> singleClick<span style="color: #666666">);</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> currentFragment<span style="color: #666666">;</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
|
|
@ -149,29 +164,31 @@ is one approach you might take.</p>
|
|||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
</code></pre></div>
|
||||
|
||||
<h2 id="in-you-custom-fragment-implement-the-goup-and-isbacktop-methods">In you custom fragment, implement the goUp and isBackTop methods</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerFragment</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerFragment <span style="color: #666666">{</span>
|
||||
<h2 id="in-your-custom-fragment-implement-the-goup-and-isbacktop-methods">In your custom fragment, implement the goUp and isBackTop methods</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #007020; font-weight: bold">package</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.examples.backbutton</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.FilePickerFragment</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">java.io.File</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerFragment</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerFragment <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * For consistency, the top level the back button checks against should be the start path.</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * But it will fall back on /.</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> */</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> File <span style="color: #06287e">getBackTop</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">if</span> <span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">containsKey</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">))</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> getPath<span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">getString</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span> <span style="color: #007020; font-weight: bold">else</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">);</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> getPath<span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">getString</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">,</span> <span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> *</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * @return true if the current path is the startpath or /</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> */</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #902000">boolean</span> <span style="color: #06287e">isBackTop</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> getBackTop<span style="color: #666666">())</span> <span style="color: #666666">||</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">));</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> getBackTop<span style="color: #666666">())</span> <span style="color: #666666">||</span>
|
||||
<span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
|
|
@ -181,10 +198,37 @@ is one approach you might take.</p>
|
|||
mCurrentPath <span style="color: #666666">=</span> getParent<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">);</span>
|
||||
mCheckedItems<span style="color: #666666">.</span><span style="color: #4070a0">clear</span><span style="color: #666666">();</span>
|
||||
mCheckedVisibleViewHolders<span style="color: #666666">.</span><span style="color: #4070a0">clear</span><span style="color: #666666">();</span>
|
||||
refresh<span style="color: #666666">();</span>
|
||||
refresh<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">);</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
</code></pre></div>
|
||||
|
||||
<h2 id="example-manifest">Example manifest</h2>
|
||||
|
||||
<p>Make sure <code>android-theme</code> points to the correct theme.</p>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #062873; font-weight: bold">&lt;manifest</span> <span style="color: #4070a0">xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span>
|
||||
<span style="color: #4070a0">package=&quot;com.nononsenseapps.filepicker.examples&quot;</span><span style="color: #062873; font-weight: bold">&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;uses-permission</span> <span style="color: #4070a0">android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;</span> <span style="color: #062873; font-weight: bold">/&gt;</span>
|
||||
<span style="color: #60a0b0; font-style: italic">&lt;!-- Only needed to create sub directories. --&gt;</span>
|
||||
<span style="color: #062873; font-weight: bold">&lt;uses-permission</span> <span style="color: #4070a0">android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;</span> <span style="color: #062873; font-weight: bold">/&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;application</span>
|
||||
<span style="color: #4070a0">android:allowBackup=&quot;true&quot;</span>
|
||||
<span style="color: #4070a0">android:icon=&quot;@mipmap/ic_launcher&quot;</span>
|
||||
<span style="color: #4070a0">android:label=&quot;@string/app_name&quot;</span>
|
||||
<span style="color: #4070a0">android:supportsRtl=&quot;true&quot;</span>
|
||||
<span style="color: #4070a0">android:theme=&quot;@style/FilePickerTheme&quot;</span><span style="color: #062873; font-weight: bold">&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;activity</span>
|
||||
<span style="color: #4070a0">android:name=&quot;.backbutton.BackHandlingFilePickerActivity&quot;</span>
|
||||
<span style="color: #4070a0">android:label=&quot;Override back button&quot;</span>
|
||||
<span style="color: #4070a0">android:theme=&quot;@style/FilePickerTheme&quot;</span><span style="color: #062873; font-weight: bold">&gt;</span>
|
||||
<span style="color: #062873; font-weight: bold">&lt;/activity&gt;</span>
|
||||
<span style="color: #062873; font-weight: bold">&lt;/application&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;/manifest&gt;</span>
|
||||
</code></pre></div>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
|
|
@ -442,58 +486,6 @@ and
|
|||
</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Customizing the filepicker</title>
|
||||
<link>http://spacecowboy.github.io/NoNonsense-FilePicker/example/</link>
|
||||
<pubDate>Sat, 16 Jul 2016 17:12:51 +0200</pubDate>
|
||||
|
||||
<guid>http://spacecowboy.github.io/NoNonsense-FilePicker/example/</guid>
|
||||
<description>
|
||||
|
||||
<p>Extend <code>AbstractFilePickerActivity</code> and implement <code>getFragment</code>. It
|
||||
should return an instance of <code>AbstractFilePickerFragment</code>. This
|
||||
basically means that the activity is just the same boilerplate with as
|
||||
single line changed (see the sample app&rsquo;s Dropbox example for an
|
||||
activity which actually has to do some extra work):</p>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #60a0b0; font-style: italic">// Making a custom SD-card picker</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">MyPickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> AbstractFilePickerActivity<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #06287e">MyPickerActivity</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">super</span><span style="color: #666666">();</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #555555; font-weight: bold">@Override</span>
|
||||
<span style="color: #007020; font-weight: bold">protected</span> AbstractFilePickerFragment<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> <span style="color: #06287e">getFragment</span><span style="color: #666666">(</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> String startPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">int</span> mode<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowMultiple<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowCreateDir<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// Only the fragment in this line needs to be changed</span>
|
||||
AbstractFilePickerFragment<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> fragment <span style="color: #666666">=</span> <span style="color: #007020; font-weight: bold">new</span> MyPickerFragment<span style="color: #666666">();</span>
|
||||
fragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>startPath<span style="color: #666666">,</span> mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowCreateDir<span style="color: #666666">);</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> fragment<span style="color: #666666">;</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
|
||||
<h3 id="extend-abstractfilepickerfragment">Extend AbstractFilePickerFragment</h3>
|
||||
|
||||
<p>Which requires you to implement</p>
|
||||
|
||||
<ul>
|
||||
<li>onNewFolder</li>
|
||||
<li>isDir</li>
|
||||
<li>getParent</li>
|
||||
<li>getPath</li>
|
||||
<li>getFullPath</li>
|
||||
<li>getName</li>
|
||||
<li>getRoot</li>
|
||||
<li>toUri</li>
|
||||
<li>getLoader</li>
|
||||
</ul>
|
||||
|
||||
<p>If you only want to make a custom SD-card picker, you can instead extend <code>FilePickerFragment</code>, and only override the relevant method you want to change.</p>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Change the sort order</title>
|
||||
<link>http://spacecowboy.github.io/NoNonsense-FilePicker/example/sortorder/</link>
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>Override the back button - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -337,11 +338,20 @@
|
|||
|
||||
|
||||
|
||||
<p>In case you want the back button navigate the hierarchy instead of instantly exiting the activity, this
|
||||
is one approach you might take.</p>
|
||||
<p>In case you want the back button to navigate the hierarchy instead of
|
||||
instantly exiting the activity, this is one approach you might take.</p>
|
||||
|
||||
<h2 id="create-an-activity-which-overrides-the-back-button-and-loads-a-custom-fragment">Create an activity which overrides the back button, and loads a custom fragment</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerActivity <span style="color: #666666">{</span>
|
||||
<h2 id="create-an-activity-which-overrides-the-back-button-and-loads-a-custom-fragment">Create an activity which overrides the back button and loads a custom fragment</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #007020; font-weight: bold">package</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.examples.backbutton</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">android.os.Environment</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.AbstractFilePickerFragment</span><span style="color: #666666">;</span>
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.FilePickerActivity</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">java.io.File</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerActivity <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * Need access to the fragment</span>
|
||||
|
|
@ -354,11 +364,17 @@ is one approach you might take.</p>
|
|||
<span style="color: #555555; font-weight: bold">@Override</span>
|
||||
<span style="color: #007020; font-weight: bold">protected</span> AbstractFilePickerFragment<span style="color: #666666"><</span>File<span style="color: #666666">></span> <span style="color: #06287e">getFragment</span><span style="color: #666666">(</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> String startPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">int</span> mode<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowMultiple<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowCreateDir<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowDirCreate<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowExistingFile<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> singleClick<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">// startPath is allowed to be null.</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// In that case, default folder should be SD-card and not "/"</span>
|
||||
String path <span style="color: #666666">=</span> <span style="color: #666666">(</span>startPath <span style="color: #666666">!=</span> <span style="color: #007020; font-weight: bold">null</span> <span style="color: #666666">?</span> startPath
|
||||
<span style="color: #666666">:</span> Environment<span style="color: #666666">.</span><span style="color: #4070a0">getExternalStorageDirectory</span><span style="color: #666666">().</span><span style="color: #4070a0">getPath</span><span style="color: #666666">());</span>
|
||||
|
||||
currentFragment <span style="color: #666666">=</span> <span style="color: #007020; font-weight: bold">new</span> BackHandlingFilePickerFragment<span style="color: #666666">();</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"</span>
|
||||
currentFragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>startPath <span style="color: #666666">!=</span> <span style="color: #007020; font-weight: bold">null</span> <span style="color: #666666">?</span> startPath <span style="color: #666666">:</span> Environment<span style="color: #666666">.</span><span style="color: #4070a0">getExternalStorageDirectory</span><span style="color: #666666">().</span><span style="color: #4070a0">getPath</span><span style="color: #666666">(),</span>
|
||||
mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowCreateDir<span style="color: #666666">);</span>
|
||||
currentFragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>path<span style="color: #666666">,</span> mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowDirCreate<span style="color: #666666">,</span>
|
||||
allowExistingFile<span style="color: #666666">,</span> singleClick<span style="color: #666666">);</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> currentFragment<span style="color: #666666">;</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
|
|
@ -376,29 +392,31 @@ is one approach you might take.</p>
|
|||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
</code></pre></div>
|
||||
|
||||
<h2 id="in-you-custom-fragment-implement-the-goup-and-isbacktop-methods">In you custom fragment, implement the goUp and isBackTop methods</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerFragment</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerFragment <span style="color: #666666">{</span>
|
||||
<h2 id="in-your-custom-fragment-implement-the-goup-and-isbacktop-methods">In your custom fragment, implement the goUp and isBackTop methods</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #007020; font-weight: bold">package</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.examples.backbutton</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.FilePickerFragment</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">java.io.File</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerFragment</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerFragment <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * For consistency, the top level the back button checks against should be the start path.</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * But it will fall back on /.</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> */</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> File <span style="color: #06287e">getBackTop</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">if</span> <span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">containsKey</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">))</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> getPath<span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">getString</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span> <span style="color: #007020; font-weight: bold">else</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">"/"</span><span style="color: #666666">);</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> getPath<span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">getString</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">,</span> <span style="color: #4070a0">"/"</span><span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> *</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * @return true if the current path is the startpath or /</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> */</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #902000">boolean</span> <span style="color: #06287e">isBackTop</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> getBackTop<span style="color: #666666">())</span> <span style="color: #666666">||</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">"/"</span><span style="color: #666666">));</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> getBackTop<span style="color: #666666">())</span> <span style="color: #666666">||</span>
|
||||
<span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">"/"</span><span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
|
|
@ -408,10 +426,37 @@ is one approach you might take.</p>
|
|||
mCurrentPath <span style="color: #666666">=</span> getParent<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">);</span>
|
||||
mCheckedItems<span style="color: #666666">.</span><span style="color: #4070a0">clear</span><span style="color: #666666">();</span>
|
||||
mCheckedVisibleViewHolders<span style="color: #666666">.</span><span style="color: #4070a0">clear</span><span style="color: #666666">();</span>
|
||||
refresh<span style="color: #666666">();</span>
|
||||
refresh<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">);</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
</code></pre></div>
|
||||
|
||||
<h2 id="example-manifest">Example manifest</h2>
|
||||
|
||||
<p>Make sure <code>android-theme</code> points to the correct theme.</p>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #062873; font-weight: bold"><manifest</span> <span style="color: #4070a0">xmlns:android="http://schemas.android.com/apk/res/android"</span>
|
||||
<span style="color: #4070a0">package="com.nononsenseapps.filepicker.examples"</span><span style="color: #062873; font-weight: bold">></span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold"><uses-permission</span> <span style="color: #4070a0">android:name="android.permission.READ_EXTERNAL_STORAGE"</span> <span style="color: #062873; font-weight: bold">/></span>
|
||||
<span style="color: #60a0b0; font-style: italic"><!-- Only needed to create sub directories. --></span>
|
||||
<span style="color: #062873; font-weight: bold"><uses-permission</span> <span style="color: #4070a0">android:name="android.permission.WRITE_EXTERNAL_STORAGE"</span> <span style="color: #062873; font-weight: bold">/></span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold"><application</span>
|
||||
<span style="color: #4070a0">android:allowBackup="true"</span>
|
||||
<span style="color: #4070a0">android:icon="@mipmap/ic_launcher"</span>
|
||||
<span style="color: #4070a0">android:label="@string/app_name"</span>
|
||||
<span style="color: #4070a0">android:supportsRtl="true"</span>
|
||||
<span style="color: #4070a0">android:theme="@style/FilePickerTheme"</span><span style="color: #062873; font-weight: bold">></span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold"><activity</span>
|
||||
<span style="color: #4070a0">android:name=".backbutton.BackHandlingFilePickerActivity"</span>
|
||||
<span style="color: #4070a0">android:label="Override back button"</span>
|
||||
<span style="color: #4070a0">android:theme="@style/FilePickerTheme"</span><span style="color: #062873; font-weight: bold">></span>
|
||||
<span style="color: #062873; font-weight: bold"></activity></span>
|
||||
<span style="color: #062873; font-weight: bold"></application></span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold"></manifest></span>
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<aside class="copyright" role="note">
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>Override selection behavior - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>Change the sort order - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -448,7 +449,7 @@
|
|||
<nav class="pagination" aria-label="Footer">
|
||||
<div class="previous">
|
||||
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/" title="Customizing the filepicker">
|
||||
<a href="http://spacecowboy.github.io/NoNonsense-FilePicker/example/custom_item_layout/" title="Custom item layout">
|
||||
<span class="direction">
|
||||
Previous
|
||||
</span>
|
||||
|
|
@ -458,7 +459,7 @@
|
|||
</div>
|
||||
<div class="stretch">
|
||||
<div class="title">
|
||||
Customizing the filepicker
|
||||
Custom item layout
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>Standalone fragment - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
|
@ -0,0 +1,61 @@
|
|||
.codehilite .hll { background-color: #ffffcc }
|
||||
.codehilite .c { color: #60a0b0; font-style: italic } /* Comment */
|
||||
.codehilite .err { border: 1px solid #FF0000 } /* Error */
|
||||
.codehilite .k { color: #007020; font-weight: bold } /* Keyword */
|
||||
.codehilite .o { color: #666666 } /* Operator */
|
||||
.codehilite .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
|
||||
.codehilite .cp { color: #007020 } /* Comment.Preproc */
|
||||
.codehilite .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
|
||||
.codehilite .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
|
||||
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
|
||||
.codehilite .ge { font-style: italic } /* Generic.Emph */
|
||||
.codehilite .gr { color: #FF0000 } /* Generic.Error */
|
||||
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
|
||||
.codehilite .go { color: #808080 } /* Generic.Output */
|
||||
.codehilite .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
|
||||
.codehilite .gs { font-weight: bold } /* Generic.Strong */
|
||||
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
|
||||
.codehilite .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
|
||||
.codehilite .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
|
||||
.codehilite .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
|
||||
.codehilite .kp { color: #007020 } /* Keyword.Pseudo */
|
||||
.codehilite .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
|
||||
.codehilite .kt { color: #902000 } /* Keyword.Type */
|
||||
.codehilite .m { color: #40a070 } /* Literal.Number */
|
||||
.codehilite .s { color: #4070a0 } /* Literal.String */
|
||||
.codehilite .na { color: #4070a0 } /* Name.Attribute */
|
||||
.codehilite .nb { color: #007020 } /* Name.Builtin */
|
||||
.codehilite .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
|
||||
.codehilite .no { color: #60add5 } /* Name.Constant */
|
||||
.codehilite .nd { color: #555555; font-weight: bold } /* Name.Decorator */
|
||||
.codehilite .ni { color: #d55537; font-weight: bold } /* Name.Entity */
|
||||
.codehilite .ne { color: #007020 } /* Name.Exception */
|
||||
.codehilite .nf { color: #06287e } /* Name.Function */
|
||||
.codehilite .nl { color: #002070; font-weight: bold } /* Name.Label */
|
||||
.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
|
||||
.codehilite .nt { color: #062873; font-weight: bold } /* Name.Tag */
|
||||
.codehilite .nv { color: #bb60d5 } /* Name.Variable */
|
||||
.codehilite .ow { color: #007020; font-weight: bold } /* Operator.Word */
|
||||
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
.codehilite .mf { color: #40a070 } /* Literal.Number.Float */
|
||||
.codehilite .mh { color: #40a070 } /* Literal.Number.Hex */
|
||||
.codehilite .mi { color: #40a070 } /* Literal.Number.Integer */
|
||||
.codehilite .mo { color: #40a070 } /* Literal.Number.Oct */
|
||||
.codehilite .sb { color: #4070a0 } /* Literal.String.Backtick */
|
||||
.codehilite .sc { color: #4070a0 } /* Literal.String.Char */
|
||||
.codehilite .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
|
||||
.codehilite .s2 { color: #4070a0 } /* Literal.String.Double */
|
||||
.codehilite .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
|
||||
.codehilite .sh { color: #4070a0 } /* Literal.String.Heredoc */
|
||||
.codehilite .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
|
||||
.codehilite .sx { color: #c65d09 } /* Literal.String.Other */
|
||||
.codehilite .sr { color: #235388 } /* Literal.String.Regex */
|
||||
.codehilite .s1 { color: #4070a0 } /* Literal.String.Single */
|
||||
.codehilite .ss { color: #517918 } /* Literal.String.Symbol */
|
||||
.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
|
||||
.codehilite .vc { color: #bb60d5 } /* Name.Variable.Class */
|
||||
.codehilite .vg { color: #bb60d5 } /* Name.Variable.Global */
|
||||
.codehilite .vi { color: #bb60d5 } /* Name.Variable.Instance */
|
||||
.codehilite .il { color: #40a070 } /* Literal.Number.Integer.Long */
|
||||
|
Before Width: | Height: | Size: 254 KiB After Width: | Height: | Size: 254 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 145 KiB |
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -110,11 +110,20 @@
|
|||
<guid>http://spacecowboy.github.io/NoNonsense-FilePicker/example/override_back_button/</guid>
|
||||
<description>
|
||||
|
||||
<p>In case you want the back button navigate the hierarchy instead of instantly exiting the activity, this
|
||||
is one approach you might take.</p>
|
||||
<p>In case you want the back button to navigate the hierarchy instead of
|
||||
instantly exiting the activity, this is one approach you might take.</p>
|
||||
|
||||
<h2 id="create-an-activity-which-overrides-the-back-button-and-loads-a-custom-fragment">Create an activity which overrides the back button, and loads a custom fragment</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerActivity <span style="color: #666666">{</span>
|
||||
<h2 id="create-an-activity-which-overrides-the-back-button-and-loads-a-custom-fragment">Create an activity which overrides the back button and loads a custom fragment</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #007020; font-weight: bold">package</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.examples.backbutton</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">android.os.Environment</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.AbstractFilePickerFragment</span><span style="color: #666666">;</span>
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.FilePickerActivity</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">java.io.File</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerActivity <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * Need access to the fragment</span>
|
||||
|
|
@ -127,11 +136,17 @@ is one approach you might take.</p>
|
|||
<span style="color: #555555; font-weight: bold">@Override</span>
|
||||
<span style="color: #007020; font-weight: bold">protected</span> AbstractFilePickerFragment<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> <span style="color: #06287e">getFragment</span><span style="color: #666666">(</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> String startPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">int</span> mode<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowMultiple<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowCreateDir<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowDirCreate<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowExistingFile<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> singleClick<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">// startPath is allowed to be null.</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// In that case, default folder should be SD-card and not &quot;/&quot;</span>
|
||||
String path <span style="color: #666666">=</span> <span style="color: #666666">(</span>startPath <span style="color: #666666">!=</span> <span style="color: #007020; font-weight: bold">null</span> <span style="color: #666666">?</span> startPath
|
||||
<span style="color: #666666">:</span> Environment<span style="color: #666666">.</span><span style="color: #4070a0">getExternalStorageDirectory</span><span style="color: #666666">().</span><span style="color: #4070a0">getPath</span><span style="color: #666666">());</span>
|
||||
|
||||
currentFragment <span style="color: #666666">=</span> <span style="color: #007020; font-weight: bold">new</span> BackHandlingFilePickerFragment<span style="color: #666666">();</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// startPath is allowed to be null. In that case, default folder should be SD-card and not &quot;/&quot;</span>
|
||||
currentFragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>startPath <span style="color: #666666">!=</span> <span style="color: #007020; font-weight: bold">null</span> <span style="color: #666666">?</span> startPath <span style="color: #666666">:</span> Environment<span style="color: #666666">.</span><span style="color: #4070a0">getExternalStorageDirectory</span><span style="color: #666666">().</span><span style="color: #4070a0">getPath</span><span style="color: #666666">(),</span>
|
||||
mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowCreateDir<span style="color: #666666">);</span>
|
||||
currentFragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>path<span style="color: #666666">,</span> mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowDirCreate<span style="color: #666666">,</span>
|
||||
allowExistingFile<span style="color: #666666">,</span> singleClick<span style="color: #666666">);</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> currentFragment<span style="color: #666666">;</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
|
|
@ -149,29 +164,31 @@ is one approach you might take.</p>
|
|||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
</code></pre></div>
|
||||
|
||||
<h2 id="in-you-custom-fragment-implement-the-goup-and-isbacktop-methods">In you custom fragment, implement the goUp and isBackTop methods</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerFragment</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerFragment <span style="color: #666666">{</span>
|
||||
<h2 id="in-your-custom-fragment-implement-the-goup-and-isbacktop-methods">In your custom fragment, implement the goUp and isBackTop methods</h2>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #007020; font-weight: bold">package</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.examples.backbutton</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">com.nononsenseapps.filepicker.FilePickerFragment</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">java.io.File</span><span style="color: #666666">;</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">BackHandlingFilePickerFragment</span> <span style="color: #007020; font-weight: bold">extends</span> FilePickerFragment <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * For consistency, the top level the back button checks against should be the start path.</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * But it will fall back on /.</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> */</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> File <span style="color: #06287e">getBackTop</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">if</span> <span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">containsKey</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">))</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> getPath<span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">getString</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span> <span style="color: #007020; font-weight: bold">else</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">);</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> getPath<span style="color: #666666">(</span>getArguments<span style="color: #666666">().</span><span style="color: #4070a0">getString</span><span style="color: #666666">(</span>KEY_START_PATH<span style="color: #666666">,</span> <span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> *</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> * @return true if the current path is the startpath or /</span>
|
||||
<span style="color: #60a0b0; font-style: italic"> */</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #902000">boolean</span> <span style="color: #06287e">isBackTop</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> getBackTop<span style="color: #666666">())</span> <span style="color: #666666">||</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">));</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> <span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> getBackTop<span style="color: #666666">())</span> <span style="color: #666666">||</span>
|
||||
<span style="color: #40a070">0</span> <span style="color: #666666">==</span> compareFiles<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">new</span> File<span style="color: #666666">(</span><span style="color: #4070a0">&quot;/&quot;</span><span style="color: #666666">));</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #60a0b0; font-style: italic">/**</span>
|
||||
|
|
@ -181,10 +198,37 @@ is one approach you might take.</p>
|
|||
mCurrentPath <span style="color: #666666">=</span> getParent<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">);</span>
|
||||
mCheckedItems<span style="color: #666666">.</span><span style="color: #4070a0">clear</span><span style="color: #666666">();</span>
|
||||
mCheckedVisibleViewHolders<span style="color: #666666">.</span><span style="color: #4070a0">clear</span><span style="color: #666666">();</span>
|
||||
refresh<span style="color: #666666">();</span>
|
||||
refresh<span style="color: #666666">(</span>mCurrentPath<span style="color: #666666">);</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
</code></pre></div>
|
||||
|
||||
<h2 id="example-manifest">Example manifest</h2>
|
||||
|
||||
<p>Make sure <code>android-theme</code> points to the correct theme.</p>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><code><span></span><span style="color: #062873; font-weight: bold">&lt;manifest</span> <span style="color: #4070a0">xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span>
|
||||
<span style="color: #4070a0">package=&quot;com.nononsenseapps.filepicker.examples&quot;</span><span style="color: #062873; font-weight: bold">&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;uses-permission</span> <span style="color: #4070a0">android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;</span> <span style="color: #062873; font-weight: bold">/&gt;</span>
|
||||
<span style="color: #60a0b0; font-style: italic">&lt;!-- Only needed to create sub directories. --&gt;</span>
|
||||
<span style="color: #062873; font-weight: bold">&lt;uses-permission</span> <span style="color: #4070a0">android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;</span> <span style="color: #062873; font-weight: bold">/&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;application</span>
|
||||
<span style="color: #4070a0">android:allowBackup=&quot;true&quot;</span>
|
||||
<span style="color: #4070a0">android:icon=&quot;@mipmap/ic_launcher&quot;</span>
|
||||
<span style="color: #4070a0">android:label=&quot;@string/app_name&quot;</span>
|
||||
<span style="color: #4070a0">android:supportsRtl=&quot;true&quot;</span>
|
||||
<span style="color: #4070a0">android:theme=&quot;@style/FilePickerTheme&quot;</span><span style="color: #062873; font-weight: bold">&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;activity</span>
|
||||
<span style="color: #4070a0">android:name=&quot;.backbutton.BackHandlingFilePickerActivity&quot;</span>
|
||||
<span style="color: #4070a0">android:label=&quot;Override back button&quot;</span>
|
||||
<span style="color: #4070a0">android:theme=&quot;@style/FilePickerTheme&quot;</span><span style="color: #062873; font-weight: bold">&gt;</span>
|
||||
<span style="color: #062873; font-weight: bold">&lt;/activity&gt;</span>
|
||||
<span style="color: #062873; font-weight: bold">&lt;/application&gt;</span>
|
||||
|
||||
<span style="color: #062873; font-weight: bold">&lt;/manifest&gt;</span>
|
||||
</code></pre></div>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
|
|
@ -442,58 +486,6 @@ and
|
|||
</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Customizing the filepicker</title>
|
||||
<link>http://spacecowboy.github.io/NoNonsense-FilePicker/example/</link>
|
||||
<pubDate>Sat, 16 Jul 2016 17:12:51 +0200</pubDate>
|
||||
|
||||
<guid>http://spacecowboy.github.io/NoNonsense-FilePicker/example/</guid>
|
||||
<description>
|
||||
|
||||
<p>Extend <code>AbstractFilePickerActivity</code> and implement <code>getFragment</code>. It
|
||||
should return an instance of <code>AbstractFilePickerFragment</code>. This
|
||||
basically means that the activity is just the same boilerplate with as
|
||||
single line changed (see the sample app&rsquo;s Dropbox example for an
|
||||
activity which actually has to do some extra work):</p>
|
||||
<div class="highlight" style="background: #f0f0f0"><pre style="line-height: 125%"><span></span><span style="color: #60a0b0; font-style: italic">// Making a custom SD-card picker</span>
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #007020; font-weight: bold">class</span> <span style="color: #0e84b5; font-weight: bold">MyPickerActivity</span> <span style="color: #007020; font-weight: bold">extends</span> AbstractFilePickerActivity<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> <span style="color: #666666">{</span>
|
||||
|
||||
<span style="color: #007020; font-weight: bold">public</span> <span style="color: #06287e">MyPickerActivity</span><span style="color: #666666">()</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #007020; font-weight: bold">super</span><span style="color: #666666">();</span>
|
||||
<span style="color: #666666">}</span>
|
||||
|
||||
<span style="color: #555555; font-weight: bold">@Override</span>
|
||||
<span style="color: #007020; font-weight: bold">protected</span> AbstractFilePickerFragment<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> <span style="color: #06287e">getFragment</span><span style="color: #666666">(</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> String startPath<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">int</span> mode<span style="color: #666666">,</span> <span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowMultiple<span style="color: #666666">,</span>
|
||||
<span style="color: #007020; font-weight: bold">final</span> <span style="color: #902000">boolean</span> allowCreateDir<span style="color: #666666">)</span> <span style="color: #666666">{</span>
|
||||
<span style="color: #60a0b0; font-style: italic">// Only the fragment in this line needs to be changed</span>
|
||||
AbstractFilePickerFragment<span style="color: #666666">&lt;</span>File<span style="color: #666666">&gt;</span> fragment <span style="color: #666666">=</span> <span style="color: #007020; font-weight: bold">new</span> MyPickerFragment<span style="color: #666666">();</span>
|
||||
fragment<span style="color: #666666">.</span><span style="color: #4070a0">setArgs</span><span style="color: #666666">(</span>startPath<span style="color: #666666">,</span> mode<span style="color: #666666">,</span> allowMultiple<span style="color: #666666">,</span> allowCreateDir<span style="color: #666666">);</span>
|
||||
<span style="color: #007020; font-weight: bold">return</span> fragment<span style="color: #666666">;</span>
|
||||
<span style="color: #666666">}</span>
|
||||
<span style="color: #666666">}</span>
|
||||
</pre></div>
|
||||
|
||||
<h3 id="extend-abstractfilepickerfragment">Extend AbstractFilePickerFragment</h3>
|
||||
|
||||
<p>Which requires you to implement</p>
|
||||
|
||||
<ul>
|
||||
<li>onNewFolder</li>
|
||||
<li>isDir</li>
|
||||
<li>getParent</li>
|
||||
<li>getPath</li>
|
||||
<li>getFullPath</li>
|
||||
<li>getName</li>
|
||||
<li>getRoot</li>
|
||||
<li>toUri</li>
|
||||
<li>getLoader</li>
|
||||
</ul>
|
||||
|
||||
<p>If you only want to make a custom SD-card picker, you can instead extend <code>FilePickerFragment</code>, and only override the relevant method you want to change.</p>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Change the sort order</title>
|
||||
<link>http://spacecowboy.github.io/NoNonsense-FilePicker/example/sortorder/</link>
|
||||
|
|
@ -8,8 +8,9 @@
|
|||
<head lang="en-us">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10" />
|
||||
<title>License - NoNonsense FilePicker</title>
|
||||
<meta name="generator" content="Hugo 0.17-DEV" />
|
||||
<meta name="generator" content="Hugo 0.16" />
|
||||
|
||||
|
||||
<meta name="description" content="An extensible and flexible file-picker for Android.">
|
||||
|
|
@ -0,0 +1 @@
|
|||
<!DOCTYPE html><html><head><link rel="canonical" href="http://spacecowboy.github.io/NoNonsense-FilePicker/"/><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="refresh" content="0;url=http://spacecowboy.github.io/NoNonsense-FilePicker/" /></head></html>
|
||||
|
After Width: | Height: | Size: 370 KiB |
|
After Width: | Height: | Size: 370 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
|
@ -31,11 +31,6 @@
|
|||
<lastmod>2016-07-16T17:21:28+02:00</lastmod>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://spacecowboy.github.io/NoNonsense-FilePicker/example/</loc>
|
||||
<lastmod>2016-07-16T17:12:51+02:00</lastmod>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://spacecowboy.github.io/NoNonsense-FilePicker/example/sortorder/</loc>
|
||||
<lastmod>2016-07-16T17:10:46+02:00</lastmod>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
|
||||
# Project-wide Gradle settings.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#Mon Aug 22 14:26:52 CEST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# Generate changelog
|
||||
github_changelog_generator -u spacecowboy -p NoNonsense-FilePicker --no-issues-wo-labels --future-release 2.5.1
|
||||
|
||||
# Commit new changelog
|
||||
|
||||
# Make tag
|
||||
|
||||
# Upload to jcenter
|
||||
./gradlew clean build bintrayUpload -PdryRun=false
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
apply plugin: 'com.android.library'
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
android {
|
||||
compileSdkVersion compileSdk
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
|
||||
implementation "com.android.support:support-v4:$supportLibraryVersion"
|
||||
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /home/jonas/android-sdk-linux/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
|
||||
<manifest package="com.nononsenseapps.filepicker">
|
||||
|
||||
<application/>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.nononsenseapps.filepicker;
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An abstract base activity that handles all the fluff you don't care about.
|
||||
* <p/>
|
||||
* Usage: To start a child activity you could either use an intent starting the
|
||||
* activity directly, or you could use an implicit intent with GET_CONTENT, if
|
||||
* it
|
||||
* is also defined in your manifest. It is defined to be handled here in case
|
||||
* you
|
||||
* want the user to be able to use other file pickers on the system.
|
||||
* <p/>
|
||||
* That means using an intent with action GET_CONTENT
|
||||
* If you want to be able to select multiple items, include EXTRA_ALLOW_MULTIPLE
|
||||
* (default false).
|
||||
* <p/>
|
||||
* Some non-standard extra arguments are supported as well:
|
||||
* EXTRA_ONLY_DIRS - (default false) allows only directories to be selected.
|
||||
* EXTRA_START_PATH - (default null) which should specify the starting path.
|
||||
* EXTRA_ALLOW_EXISTING_FILE - (default true) if existing files are selectable in 'new file'-mode
|
||||
* <p/>
|
||||
* The result of the user's action is returned in onActivityResult intent,
|
||||
* access it using getUri.
|
||||
* In case of multiple choices, these can be accessed with getClipData
|
||||
* containing Uri objects.
|
||||
* If running earlier than JellyBean you can access them with
|
||||
* getStringArrayListExtra(EXTRA_PATHS)
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractFilePickerActivity<T> extends AppCompatActivity
|
||||
implements AbstractFilePickerFragment.OnFilePickedListener {
|
||||
public static final String EXTRA_START_PATH =
|
||||
"nononsense.intent" + ".START_PATH";
|
||||
public static final String EXTRA_MODE = "nononsense.intent.MODE";
|
||||
public static final String EXTRA_ALLOW_CREATE_DIR =
|
||||
"nononsense.intent" + ".ALLOW_CREATE_DIR";
|
||||
public static final String EXTRA_SINGLE_CLICK =
|
||||
"nononsense.intent" + ".SINGLE_CLICK";
|
||||
// For compatibility
|
||||
public static final String EXTRA_ALLOW_MULTIPLE =
|
||||
"android.intent.extra" + ".ALLOW_MULTIPLE";
|
||||
public static final String EXTRA_ALLOW_EXISTING_FILE =
|
||||
"android.intent.extra" + ".ALLOW_EXISTING_FILE";
|
||||
public static final String EXTRA_PATHS = "nononsense.intent.PATHS";
|
||||
public static final int MODE_FILE = AbstractFilePickerFragment.MODE_FILE;
|
||||
public static final int MODE_FILE_AND_DIR =
|
||||
AbstractFilePickerFragment.MODE_FILE_AND_DIR;
|
||||
public static final int MODE_NEW_FILE = AbstractFilePickerFragment.MODE_NEW_FILE;
|
||||
public static final int MODE_DIR = AbstractFilePickerFragment.MODE_DIR;
|
||||
protected static final String TAG = "filepicker_fragment";
|
||||
protected String startPath = null;
|
||||
protected int mode = AbstractFilePickerFragment.MODE_FILE;
|
||||
protected boolean allowCreateDir = false;
|
||||
protected boolean allowMultiple = false;
|
||||
private boolean allowExistingFile = true;
|
||||
protected boolean singleClick = false;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.nnf_activity_filepicker);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
startPath = intent.getStringExtra(EXTRA_START_PATH);
|
||||
mode = intent.getIntExtra(EXTRA_MODE, mode);
|
||||
allowCreateDir = intent.getBooleanExtra(EXTRA_ALLOW_CREATE_DIR,
|
||||
allowCreateDir);
|
||||
allowMultiple =
|
||||
intent.getBooleanExtra(EXTRA_ALLOW_MULTIPLE, allowMultiple);
|
||||
allowExistingFile =
|
||||
intent.getBooleanExtra(EXTRA_ALLOW_EXISTING_FILE, allowExistingFile);
|
||||
singleClick =
|
||||
intent.getBooleanExtra(EXTRA_SINGLE_CLICK, singleClick);
|
||||
}
|
||||
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
AbstractFilePickerFragment<T> fragment =
|
||||
(AbstractFilePickerFragment<T>) fm.findFragmentByTag(TAG);
|
||||
|
||||
if (fragment == null) {
|
||||
fragment =
|
||||
getFragment(startPath, mode, allowMultiple, allowCreateDir, allowExistingFile,
|
||||
singleClick);
|
||||
}
|
||||
|
||||
if (fragment != null) {
|
||||
fm.beginTransaction().replace(R.id.fragment, fragment, TAG)
|
||||
.commit();
|
||||
}
|
||||
|
||||
// Default to cancelled
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
}
|
||||
|
||||
protected abstract AbstractFilePickerFragment<T> getFragment(
|
||||
@Nullable final String startPath, final int mode, final boolean allowMultiple,
|
||||
final boolean allowCreateDir, final boolean allowExistingFile,
|
||||
final boolean singleClick);
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle b) {
|
||||
super.onSaveInstanceState(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFilePicked(@NonNull final Uri file) {
|
||||
Intent i = new Intent();
|
||||
i.setData(file);
|
||||
setResult(Activity.RESULT_OK, i);
|
||||
finish();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
public void onFilesPicked(@NonNull final List<Uri> files) {
|
||||
Intent i = new Intent();
|
||||
i.putExtra(EXTRA_ALLOW_MULTIPLE, true);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
ClipData clip = null;
|
||||
for (Uri file : files) {
|
||||
if (clip == null) {
|
||||
clip = new ClipData("Paths", new String[]{},
|
||||
new ClipData.Item(file));
|
||||
} else {
|
||||
clip.addItem(new ClipData.Item(file));
|
||||
}
|
||||
}
|
||||
i.setClipData(clip);
|
||||
} else {
|
||||
ArrayList<String> paths = new ArrayList<>();
|
||||
for (Uri file : files) {
|
||||
paths.add(file.toString());
|
||||
}
|
||||
i.putStringArrayListExtra(EXTRA_PATHS, paths);
|
||||
}
|
||||
|
||||
setResult(Activity.RESULT_OK, i);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled() {
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,895 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.nononsenseapps.filepicker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.util.SortedList;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static com.nononsenseapps.filepicker.Utils.appendPath;
|
||||
|
||||
/**
|
||||
* A fragment representing a list of Files.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Activities containing this fragment MUST implement the {@link
|
||||
* OnFilePickedListener}
|
||||
* interface.
|
||||
*/
|
||||
public abstract class AbstractFilePickerFragment<T> extends DialogFragment
|
||||
implements LoaderManager.LoaderCallbacks<SortedList<T>>,
|
||||
NewItemFragment.OnNewFolderListener, LogicHandler<T> {
|
||||
|
||||
// The different preset modes of operation. This impacts the behaviour
|
||||
// and possible actions in the UI.
|
||||
public static final int MODE_FILE = 0;
|
||||
public static final int MODE_DIR = 1;
|
||||
public static final int MODE_FILE_AND_DIR = 2;
|
||||
public static final int MODE_NEW_FILE = 3;
|
||||
// Where to display on open.
|
||||
public static final String KEY_START_PATH = "KEY_START_PATH";
|
||||
// See MODE_XXX constants above for possible values
|
||||
public static final String KEY_MODE = "KEY_MODE";
|
||||
// If it should be possible to create directories.
|
||||
public static final String KEY_ALLOW_DIR_CREATE = "KEY_ALLOW_DIR_CREATE";
|
||||
// Allow multiple items to be selected.
|
||||
public static final String KEY_ALLOW_MULTIPLE = "KEY_ALLOW_MULTIPLE";
|
||||
// Allow an existing file to be selected under MODE_NEW_FILE
|
||||
public static final String KEY_ALLOW_EXISTING_FILE = "KEY_ALLOW_EXISTING_FILE";
|
||||
// If file can be selected by clicking only and checkboxes are not visible
|
||||
public static final String KEY_SINGLE_CLICK = "KEY_SINGLE_CLICK";
|
||||
// Used for saving state.
|
||||
protected static final String KEY_CURRENT_PATH = "KEY_CURRENT_PATH";
|
||||
protected final HashSet<T> mCheckedItems;
|
||||
protected final HashSet<CheckableViewHolder> mCheckedVisibleViewHolders;
|
||||
protected int mode = MODE_FILE;
|
||||
protected T mCurrentPath = null;
|
||||
protected boolean allowCreateDir = false;
|
||||
protected boolean allowMultiple = false;
|
||||
protected boolean allowExistingFile = true;
|
||||
protected boolean singleClick = false;
|
||||
protected OnFilePickedListener mListener;
|
||||
protected FileItemAdapter<T> mAdapter = null;
|
||||
protected TextView mCurrentDirView;
|
||||
protected EditText mEditTextFileName;
|
||||
protected RecyclerView recyclerView;
|
||||
protected LinearLayoutManager layoutManager;
|
||||
protected SortedList<T> mFiles = null;
|
||||
protected Toast mToast = null;
|
||||
// Keep track if we are currently loading a directory, in case it takes a long time
|
||||
protected boolean isLoading = false;
|
||||
protected View mNewFileButtonContainer = null;
|
||||
protected View mRegularButtonContainer = null;
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
* fragment (e.g. upon screen orientation changes).
|
||||
*/
|
||||
public AbstractFilePickerFragment() {
|
||||
mCheckedItems = new HashSet<>();
|
||||
mCheckedVisibleViewHolders = new HashSet<>();
|
||||
|
||||
// Retain this fragment across configuration changes, to allow
|
||||
// asynctasks and such to be used with ease.
|
||||
setRetainInstance(true);
|
||||
}
|
||||
|
||||
protected FileItemAdapter<T> getAdapter() {
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
protected FileItemAdapter<T> getDummyAdapter() {
|
||||
return new FileItemAdapter<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
getContext().getTheme().applyStyle(getStyleId(), true);
|
||||
final View view = inflater.inflate(R.layout.nnf_fragment_filepicker, container, false);
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.nnf_picker_toolbar);
|
||||
if (toolbar != null) {
|
||||
setupToolbar(toolbar);
|
||||
}
|
||||
|
||||
recyclerView = (RecyclerView) view.findViewById(android.R.id.list);
|
||||
// improve performance if you know that changes in content
|
||||
// do not change the size of the RecyclerView
|
||||
recyclerView.setHasFixedSize(true);
|
||||
// use a linear layout manager
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
// Set Item Decoration if exists
|
||||
configureItemDecoration(inflater, recyclerView);
|
||||
// Set adapter
|
||||
mAdapter = new FileItemAdapter<>(this);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
view.findViewById(R.id.nnf_button_cancel)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
onClickCancel(v);
|
||||
}
|
||||
});
|
||||
|
||||
view.findViewById(R.id.nnf_button_ok).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
onClickOk(v);
|
||||
}
|
||||
});
|
||||
view.findViewById(R.id.nnf_button_ok_newfile).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onClickOk(v);
|
||||
}
|
||||
});
|
||||
|
||||
mNewFileButtonContainer = view.findViewById(R.id.nnf_newfile_button_container);
|
||||
mRegularButtonContainer = view.findViewById(R.id.nnf_button_container);
|
||||
|
||||
mEditTextFileName = (EditText) view.findViewById(R.id.nnf_text_filename);
|
||||
mEditTextFileName.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// deSelect anything selected since the user just modified the name
|
||||
clearSelections();
|
||||
}
|
||||
});
|
||||
|
||||
mCurrentDirView = (TextView) view.findViewById(R.id.nnf_current_dir);
|
||||
// Restore state
|
||||
if (mCurrentPath != null && mCurrentDirView != null) {
|
||||
mCurrentDirView.setText(getFullPath(mCurrentPath));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a divider drawable has been defined in the current theme. If it has, will apply
|
||||
* an item decoration with the divider. If no divider has been specified, then does nothing.
|
||||
*/
|
||||
protected void configureItemDecoration(@NonNull LayoutInflater inflater,
|
||||
@NonNull RecyclerView recyclerView) {
|
||||
final TypedArray attributes =
|
||||
getActivity().obtainStyledAttributes(new int[]{R.attr.nnf_list_item_divider});
|
||||
Drawable divider = attributes.getDrawable(0);
|
||||
attributes.recycle();
|
||||
|
||||
if (divider != null) {
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(divider));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the cancel-button is pressed.
|
||||
*
|
||||
* @param view which was clicked. Not used in default implementation.
|
||||
*/
|
||||
public void onClickCancel(@NonNull View view) {
|
||||
if (mListener != null) {
|
||||
mListener.onCancelled();
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the ok-button is pressed.
|
||||
*
|
||||
* @param view which was clicked. Not used in default implementation.
|
||||
*/
|
||||
public void onClickOk(@NonNull View view) {
|
||||
if (mListener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Some invalid cases first
|
||||
/*if (MODE_NEW_FILE == mode && !isValidFileName(getNewFileName())) {
|
||||
mToast = Toast.makeText(getActivity(), R.string.nnf_need_valid_filename,
|
||||
Toast.LENGTH_SHORT);
|
||||
mToast.show();
|
||||
return;
|
||||
}*/
|
||||
if ((allowMultiple || mode == MODE_FILE) &&
|
||||
(mCheckedItems.isEmpty() || getFirstCheckedItem() == null)) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(getActivity(), R.string.nnf_select_something_first,
|
||||
Toast.LENGTH_SHORT);
|
||||
}
|
||||
mToast.show();
|
||||
return;
|
||||
}
|
||||
|
||||
// New file allows only a single file
|
||||
if (mode == MODE_NEW_FILE) {
|
||||
final String filename = getNewFileName();
|
||||
final Uri result;
|
||||
if (filename.startsWith("/")) {
|
||||
// Return absolute paths directly
|
||||
result = toUri(getPath(filename));
|
||||
} else {
|
||||
// Append to current directory
|
||||
result = toUri(getPath(appendPath(getFullPath(mCurrentPath), filename)));
|
||||
}
|
||||
mListener.onFilePicked(result);
|
||||
} else if (allowMultiple) {
|
||||
mListener.onFilesPicked(toUri(mCheckedItems));
|
||||
} else if (mode == MODE_FILE) {
|
||||
//noinspection ConstantConditions
|
||||
mListener.onFilePicked(toUri(getFirstCheckedItem()));
|
||||
} else if (mode == MODE_DIR) {
|
||||
mListener.onFilePicked(toUri(mCurrentPath));
|
||||
} else {
|
||||
// single FILE OR DIR
|
||||
if (mCheckedItems.isEmpty()) {
|
||||
mListener.onFilePicked(toUri(mCurrentPath));
|
||||
} else {
|
||||
mListener.onFilePicked(toUri(getFirstCheckedItem()));
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return filename as entered/picked by the user for the new file
|
||||
*/
|
||||
@NonNull
|
||||
protected String getNewFileName() {
|
||||
return mEditTextFileName.getText().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the toolbar anyway you like here. Default is to set it as the activity's
|
||||
* main action bar. Override if you already provide an action bar.
|
||||
* Not called if no toolbar was found.
|
||||
*
|
||||
* @param toolbar from layout with id "picker_toolbar"
|
||||
*/
|
||||
protected void setupToolbar(@NonNull Toolbar toolbar) {
|
||||
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
public
|
||||
@Nullable
|
||||
T getFirstCheckedItem() {
|
||||
//noinspection LoopStatementThatDoesntLoop
|
||||
for (T file : mCheckedItems) {
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected
|
||||
@NonNull
|
||||
List<Uri> toUri(@NonNull Iterable<T> files) {
|
||||
ArrayList<Uri> uris = new ArrayList<>();
|
||||
for (T file : files) {
|
||||
uris.add(toUri(file));
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
|
||||
public boolean isCheckable(@NonNull final T data) {
|
||||
final boolean checkable;
|
||||
if (isDir(data)) {
|
||||
checkable = ((mode == MODE_DIR && allowMultiple) ||
|
||||
(mode == MODE_FILE_AND_DIR && allowMultiple));
|
||||
} else {
|
||||
// File
|
||||
checkable = (mode == MODE_FILE || mode == MODE_FILE_AND_DIR || allowExistingFile);
|
||||
}
|
||||
return checkable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
try {
|
||||
mListener = (OnFilePickedListener) context;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(context.toString() +
|
||||
" must implement OnFilePickedListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the fragment's activity has been created and this
|
||||
* fragment's view hierarchy instantiated. It can be used to do final
|
||||
* initialization once these pieces are in place, such as retrieving
|
||||
* views or restoring state. It is also useful for fragments that use
|
||||
* {@link #setRetainInstance(boolean)} to retain their instance,
|
||||
* as this callback tells the fragment when it is fully associated with
|
||||
* the new activity instance. This is called after {@link #onCreateView}
|
||||
* and before {@link #onViewStateRestored(Bundle)}.
|
||||
*
|
||||
* @param savedInstanceState If the fragment is being re-created from
|
||||
* a previous saved state, this is the state.
|
||||
*/
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
// Only if we have no state
|
||||
if (mCurrentPath == null) {
|
||||
if (savedInstanceState != null) {
|
||||
mode = savedInstanceState.getInt(KEY_MODE, mode);
|
||||
allowCreateDir = savedInstanceState
|
||||
.getBoolean(KEY_ALLOW_DIR_CREATE, allowCreateDir);
|
||||
allowMultiple = savedInstanceState
|
||||
.getBoolean(KEY_ALLOW_MULTIPLE, allowMultiple);
|
||||
allowExistingFile = savedInstanceState
|
||||
.getBoolean(KEY_ALLOW_EXISTING_FILE, allowExistingFile);
|
||||
singleClick = savedInstanceState
|
||||
.getBoolean(KEY_SINGLE_CLICK, singleClick);
|
||||
|
||||
String path = savedInstanceState.getString(KEY_CURRENT_PATH);
|
||||
if (path != null) {
|
||||
mCurrentPath = getPath(path.trim());
|
||||
}
|
||||
} else if (getArguments() != null) {
|
||||
mode = getArguments().getInt(KEY_MODE, mode);
|
||||
allowCreateDir = getArguments()
|
||||
.getBoolean(KEY_ALLOW_DIR_CREATE, allowCreateDir);
|
||||
allowMultiple = getArguments()
|
||||
.getBoolean(KEY_ALLOW_MULTIPLE, allowMultiple);
|
||||
allowExistingFile = getArguments()
|
||||
.getBoolean(KEY_ALLOW_EXISTING_FILE, allowExistingFile);
|
||||
singleClick = getArguments()
|
||||
.getBoolean(KEY_SINGLE_CLICK, singleClick);
|
||||
if (getArguments().containsKey(KEY_START_PATH)) {
|
||||
String path = getArguments().getString(KEY_START_PATH);
|
||||
if (path != null) {
|
||||
T file = getPath(path.trim());
|
||||
if (isDir(file)) {
|
||||
mCurrentPath = file;
|
||||
} else {
|
||||
mCurrentPath = getParent(file);
|
||||
mEditTextFileName.setText(getName(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setModeView(getView());
|
||||
|
||||
// If still null
|
||||
if (mCurrentPath == null) {
|
||||
mCurrentPath = getRoot();
|
||||
}
|
||||
refresh(mCurrentPath);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hides/Shows appropriate views depending on mode
|
||||
*/
|
||||
protected void setModeView(@NonNull View view) {
|
||||
boolean nf = mode == MODE_NEW_FILE;
|
||||
mNewFileButtonContainer.setVisibility(nf ? View.VISIBLE : View.GONE);
|
||||
mRegularButtonContainer.setVisibility(nf ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (!nf && singleClick) {
|
||||
view.findViewById(R.id.nnf_button_ok).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.picker_actions, menu);
|
||||
|
||||
MenuItem item = menu.findItem(R.id.nnf_action_createdir);
|
||||
item.setVisible(allowCreateDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
||||
if (R.id.nnf_action_createdir == menuItem.getItemId()) {
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof AppCompatActivity) {
|
||||
NewFolderFragment.showDialog(((AppCompatActivity) activity).getSupportFragmentManager(),
|
||||
AbstractFilePickerFragment.this);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle b) {
|
||||
super.onSaveInstanceState(b);
|
||||
b.putString(KEY_CURRENT_PATH, mCurrentPath.toString());
|
||||
b.putBoolean(KEY_ALLOW_MULTIPLE, allowMultiple);
|
||||
b.putBoolean(KEY_ALLOW_EXISTING_FILE, allowExistingFile);
|
||||
b.putBoolean(KEY_ALLOW_DIR_CREATE, allowCreateDir);
|
||||
b.putBoolean(KEY_SINGLE_CLICK, singleClick);
|
||||
b.putInt(KEY_MODE, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the list. Call this when current path changes. This method also checks
|
||||
* if permissions are granted and requests them if necessary. See hasPermission()
|
||||
* and handlePermission(). By default, these methods do nothing. Override them if
|
||||
* you need to request permissions at runtime.
|
||||
*
|
||||
* @param nextPath path to list files for
|
||||
*/
|
||||
protected void refresh(@NonNull T nextPath) {
|
||||
if (hasPermission(nextPath)) {
|
||||
mCurrentPath = nextPath;
|
||||
isLoading = true;
|
||||
getLoaderManager()
|
||||
.restartLoader(0, null, AbstractFilePickerFragment.this);
|
||||
} else {
|
||||
handlePermission(nextPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If permission has not been granted yet, this method should request it.
|
||||
* <p/>
|
||||
* Override only if you need to request a permission.
|
||||
*
|
||||
* @param path The path for which permission should be requested
|
||||
*/
|
||||
protected void handlePermission(@NonNull T path) {
|
||||
// Nothing to do by default
|
||||
}
|
||||
|
||||
/**
|
||||
* If your implementation needs to request a specific permission to function, check if it
|
||||
* has been granted here. You should probably also override handlePermission() to request it.
|
||||
*
|
||||
* @param path the path for which permissions should be checked
|
||||
* @return true if permission has been granted, false otherwise.
|
||||
*/
|
||||
protected boolean hasPermission(@NonNull T path) {
|
||||
// Nothing to request by default
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate and return a new Loader for the given ID.
|
||||
*
|
||||
* @param id The ID whose loader is to be created.
|
||||
* @param args Any arguments supplied by the caller.
|
||||
* @return Return a new Loader instance that is ready to start loading.
|
||||
*/
|
||||
@Override
|
||||
public Loader<SortedList<T>> onCreateLoader(final int id, final Bundle args) {
|
||||
return getLoader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a previously created loader has finished its load.
|
||||
*
|
||||
* @param loader The Loader that has finished.
|
||||
* @param data The data generated by the Loader.
|
||||
*/
|
||||
@Override
|
||||
public void onLoadFinished(final Loader<SortedList<T>> loader,
|
||||
final SortedList<T> data) {
|
||||
isLoading = false;
|
||||
mCheckedItems.clear();
|
||||
mCheckedVisibleViewHolders.clear();
|
||||
mFiles = data;
|
||||
mAdapter.setList(data);
|
||||
if (mCurrentDirView != null) {
|
||||
mCurrentDirView.setText(getFullPath(mCurrentPath));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a previously created loader is being reset, and thus
|
||||
* making its data unavailable. The application should at this point
|
||||
* remove any references it has to the Loader's data.
|
||||
*
|
||||
* @param loader The Loader that is being reset.
|
||||
*/
|
||||
@Override
|
||||
public void onLoaderReset(final Loader<SortedList<T>> loader) {
|
||||
isLoading = false;
|
||||
mAdapter.setList(null);
|
||||
mFiles = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param position 0 - n, where the header has been subtracted
|
||||
* @param data the actual file or directory
|
||||
* @return an integer greater than 0
|
||||
*/
|
||||
@Override
|
||||
public int getItemViewType(int position, @NonNull T data) {
|
||||
if (isCheckable(data)) {
|
||||
return LogicHandler.VIEWTYPE_CHECKABLE;
|
||||
} else {
|
||||
return LogicHandler.VIEWTYPE_DIR;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindHeaderViewHolder(@NonNull HeaderViewHolder viewHolder) {
|
||||
viewHolder.text.setText("..");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent Containing view
|
||||
* @param viewType which the ViewHolder will contain
|
||||
* @return a view holder for a file or directory
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v;
|
||||
getContext().getTheme().applyStyle(getStyleId(), true);
|
||||
switch (viewType) {
|
||||
case LogicHandler.VIEWTYPE_HEADER:
|
||||
v = LayoutInflater.from(getActivity()).inflate(R.layout.nnf_filepicker_listitem_dir,
|
||||
parent, false);
|
||||
return new HeaderViewHolder(v);
|
||||
case LogicHandler.VIEWTYPE_CHECKABLE:
|
||||
v = LayoutInflater.from(getActivity()).inflate(R.layout.nnf_filepicker_listitem_checkable,
|
||||
parent, false);
|
||||
return new CheckableViewHolder(v);
|
||||
case LogicHandler.VIEWTYPE_DIR:
|
||||
default:
|
||||
v = LayoutInflater.from(getActivity()).inflate(R.layout.nnf_filepicker_listitem_dir,
|
||||
parent, false);
|
||||
return new DirViewHolder(v);
|
||||
}
|
||||
}
|
||||
|
||||
@StyleRes
|
||||
protected abstract int getStyleId();
|
||||
|
||||
/**
|
||||
* @param vh to bind data from either a file or directory
|
||||
* @param position 0 - n, where the header has been subtracted
|
||||
* @param data the file or directory which this item represents
|
||||
*/
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DirViewHolder vh, int position, @NonNull T data) {
|
||||
vh.file = data;
|
||||
vh.icon.setVisibility(isDir(data) ? View.VISIBLE : View.GONE);
|
||||
vh.text.setText(getName(data));
|
||||
|
||||
if (isCheckable(data)) {
|
||||
if (mCheckedItems.contains(data)) {
|
||||
mCheckedVisibleViewHolders.add((CheckableViewHolder) vh);
|
||||
((CheckableViewHolder) vh).checkbox.setChecked(true);
|
||||
} else {
|
||||
//noinspection SuspiciousMethodCalls
|
||||
mCheckedVisibleViewHolders.remove(vh);
|
||||
((CheckableViewHolder) vh).checkbox.setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate de-selection of visible views and clear
|
||||
* selected set.
|
||||
*/
|
||||
public void clearSelections() {
|
||||
for (CheckableViewHolder vh : mCheckedVisibleViewHolders) {
|
||||
vh.checkbox.setChecked(false);
|
||||
}
|
||||
mCheckedVisibleViewHolders.clear();
|
||||
mCheckedItems.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when a header item ("..") is clicked.
|
||||
*
|
||||
* @param view that was clicked. Not used in default implementation.
|
||||
* @param viewHolder for the clicked view
|
||||
*/
|
||||
public void onClickHeader(@NonNull View view, @NonNull HeaderViewHolder viewHolder) {
|
||||
goUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browses to the parent directory from the current directory. For example, if the current
|
||||
* directory is /foo/bar/, then goUp() will change the current directory to /foo/. It is up to
|
||||
* the caller to not call this in vain, e.g. if you are already at the root.
|
||||
* <p/>
|
||||
* Currently selected items are cleared by this operation.
|
||||
*/
|
||||
public void goUp() {
|
||||
goToDir(getParent(mCurrentPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a non-selectable item, typically a directory, is clicked.
|
||||
*
|
||||
* @param view that was clicked. Not used in default implementation.
|
||||
* @param viewHolder for the clicked view
|
||||
*/
|
||||
public void onClickDir(@NonNull View view, @NonNull DirViewHolder viewHolder) {
|
||||
if (isDir(viewHolder.file)) {
|
||||
goToDir(viewHolder.file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cab be used by the list to determine whether a file should be displayed or not.
|
||||
* Default behavior is to always display folders. If files can be selected,
|
||||
* then files are also displayed. In case a new file is supposed to be selected,
|
||||
* the {@link #allowExistingFile} determines if existing files are visible
|
||||
*
|
||||
* @param file either a directory or file.
|
||||
* @return True if item should be visible in the picker, false otherwise
|
||||
*/
|
||||
protected boolean isItemVisible(final T file) {
|
||||
return (isDir(file) ||
|
||||
(mode == MODE_FILE || mode == MODE_FILE_AND_DIR) ||
|
||||
(mode == MODE_NEW_FILE && allowExistingFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Browses to the designated directory. It is up to the caller verify that the argument is
|
||||
* in fact a directory. If another directory is in the process of being loaded, this method
|
||||
* will not start another load.
|
||||
* <p/>
|
||||
* Currently selected items are cleared by this operation.
|
||||
*
|
||||
* @param file representing the target directory.
|
||||
*/
|
||||
public void goToDir(@NonNull T file) {
|
||||
if (!isLoading) {
|
||||
mCheckedItems.clear();
|
||||
mCheckedVisibleViewHolders.clear();
|
||||
refresh(file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Long clicking a non-selectable item does nothing by default.
|
||||
*
|
||||
* @param view which was long clicked. Not used in default implementation.
|
||||
* @param viewHolder for the clicked view
|
||||
* @return true if the callback consumed the long click, false otherwise.
|
||||
*/
|
||||
public boolean onLongClickDir(@NonNull View view, @NonNull DirViewHolder viewHolder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a selectable item is clicked. This might be either a file or a directory.
|
||||
*
|
||||
* @param view that was clicked. Not used in default implementation.
|
||||
* @param viewHolder for the clicked view
|
||||
*/
|
||||
public void onClickCheckable(@NonNull View view, @NonNull CheckableViewHolder viewHolder) {
|
||||
if (isDir(viewHolder.file)) {
|
||||
goToDir(viewHolder.file);
|
||||
} else {
|
||||
onLongClickCheckable(view, viewHolder);
|
||||
if (singleClick) {
|
||||
onClickOk(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Long clicking a selectable item should toggle its selected state. Note that if only a
|
||||
* single item can be selected, then other potentially selected views on screen must be
|
||||
* de-selected.
|
||||
*
|
||||
* @param view which was long clicked. Not used in default implementation.
|
||||
* @param viewHolder for the clicked view
|
||||
* @return true if the callback consumed the long click, false otherwise.
|
||||
*/
|
||||
public boolean onLongClickCheckable(@NonNull View view,
|
||||
@NonNull CheckableViewHolder viewHolder) {
|
||||
if (MODE_NEW_FILE == mode) {
|
||||
mEditTextFileName.setText(getName(viewHolder.file));
|
||||
}
|
||||
onClickCheckBox(viewHolder);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a selectable item's checkbox is pressed. This should toggle its selected state.
|
||||
* Note that if only a single item can be selected, then other potentially selected views on
|
||||
* screen must be de-selected. The text box for new filename is also cleared.
|
||||
*
|
||||
* @param viewHolder for the item containing the checkbox.
|
||||
*/
|
||||
public void onClickCheckBox(@NonNull CheckableViewHolder viewHolder) {
|
||||
if (mCheckedItems.contains(viewHolder.file)) {
|
||||
viewHolder.checkbox.setChecked(false);
|
||||
mCheckedItems.remove(viewHolder.file);
|
||||
mCheckedVisibleViewHolders.remove(viewHolder);
|
||||
} else {
|
||||
if (!allowMultiple) {
|
||||
clearSelections();
|
||||
}
|
||||
viewHolder.checkbox.setChecked(true);
|
||||
mCheckedItems.add(viewHolder.file);
|
||||
mCheckedVisibleViewHolders.add(viewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface must be implemented by activities that contain this
|
||||
* fragment to allow an interaction in this fragment to be communicated
|
||||
* to the activity and potentially other fragments contained in that
|
||||
* activity.
|
||||
* <p/>
|
||||
* See the Android Training lesson <a href=
|
||||
* "http://developer.android.com/training/basics/fragments/communicating
|
||||
* .html"
|
||||
* >Communicating with Other Fragments</a> for more information.
|
||||
*/
|
||||
public interface OnFilePickedListener {
|
||||
void onFilePicked(@NonNull Uri file);
|
||||
|
||||
void onFilesPicked(@NonNull List<Uri> files);
|
||||
|
||||
void onCancelled();
|
||||
}
|
||||
|
||||
public class HeaderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
final TextView text;
|
||||
|
||||
public HeaderViewHolder(View v) {
|
||||
super(v);
|
||||
v.setOnClickListener(this);
|
||||
text = (TextView) v.findViewById(android.R.id.text1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a view has been clicked.
|
||||
*
|
||||
* @param v The view that was clicked.
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onClickHeader(v, this);
|
||||
}
|
||||
}
|
||||
|
||||
public class DirViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,
|
||||
View.OnLongClickListener {
|
||||
|
||||
public View icon;
|
||||
public TextView text;
|
||||
public T file;
|
||||
|
||||
public DirViewHolder(View v) {
|
||||
super(v);
|
||||
v.setOnClickListener(this);
|
||||
v.setOnLongClickListener(this);
|
||||
icon = v.findViewById(R.id.item_icon);
|
||||
text = (TextView) v.findViewById(android.R.id.text1);
|
||||
text.setTextColor(ContextCompat.getColor(getActivity(), android.R.color.white));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a view has been clicked.
|
||||
*
|
||||
* @param v The view that was clicked.
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onClickDir(v, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a view has been clicked and held.
|
||||
*
|
||||
* @param v The view that was clicked and held.
|
||||
* @return true if the callback consumed the long click, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
return onLongClickDir(v, this);
|
||||
}
|
||||
}
|
||||
|
||||
public class CheckableViewHolder extends DirViewHolder {
|
||||
|
||||
public CheckBox checkbox;
|
||||
|
||||
public CheckableViewHolder(View v) {
|
||||
super(v);
|
||||
boolean nf = mode == MODE_NEW_FILE;
|
||||
|
||||
checkbox = (CheckBox) v.findViewById(R.id.checkbox);
|
||||
checkbox.setVisibility((nf || singleClick) ? View.GONE : View.VISIBLE);
|
||||
checkbox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onClickCheckBox(CheckableViewHolder.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a view has been clicked.
|
||||
*
|
||||
* @param v The view that was clicked.
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onClickCheckable(v, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a view has been clicked and held.
|
||||
*
|
||||
* @param v The view that was clicked and held.
|
||||
* @return true if the callback consumed the long click, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
return onLongClickCheckable(v, this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.nononsenseapps.filepicker;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Basic ItemDecoration which loads a drawable as a divider.
|
||||
*/
|
||||
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||
private Drawable mDivider;
|
||||
|
||||
public DividerItemDecoration(Drawable divider) {
|
||||
mDivider = divider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
|
||||
if (parent.getChildAdapterPosition(view) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
outRect.top = mDivider.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
|
||||
int dividerLeft = parent.getPaddingLeft();
|
||||
int dividerRight = parent.getWidth() - parent.getPaddingRight();
|
||||
|
||||
int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount - 1; i++) {
|
||||
View child = parent.getChildAt(i);
|
||||
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
int dividerTop = child.getBottom() + params.bottomMargin;
|
||||
int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();
|
||||
|
||||
mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
|
||||
mDivider.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.nononsenseapps.filepicker;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.util.SortedList;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* A simple adapter which also inserts a header item ".." to handle going up to the parent folder.
|
||||
* @param <T> the type which is used, for example a normal java File object.
|
||||
*/
|
||||
public class FileItemAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
protected final LogicHandler<T> mLogic;
|
||||
protected SortedList<T> mList = null;
|
||||
|
||||
public FileItemAdapter(@NonNull LogicHandler<T> logic) {
|
||||
this.mLogic = logic;
|
||||
}
|
||||
|
||||
public void setList(@Nullable SortedList<T> list) {
|
||||
mList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return mLogic.onCreateViewHolder(parent, viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int headerPosition) {
|
||||
if (headerPosition == 0) {
|
||||
mLogic.onBindHeaderViewHolder((AbstractFilePickerFragment<T>.HeaderViewHolder) viewHolder);
|
||||
} else {
|
||||
int pos = headerPosition - 1;
|
||||
mLogic.onBindViewHolder((AbstractFilePickerFragment<T>.DirViewHolder) viewHolder, pos, mList.get(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int headerPosition) {
|
||||
if (0 == headerPosition) {
|
||||
return LogicHandler.VIEWTYPE_HEADER;
|
||||
} else {
|
||||
int pos = headerPosition - 1;
|
||||
return mLogic.getItemViewType(pos, mList.get(pos));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mList == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// header + count
|
||||
return 1 + mList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item at the designated position in the adapter.
|
||||
*
|
||||
* @param position of item in adapter
|
||||
* @return null if position is zero (that means it's the ".." header), the item otherwise.
|
||||
*/
|
||||
protected @Nullable T getItem(int position) {
|
||||
if (position == 0) {
|
||||
return null;
|
||||
}
|
||||
return mList.get(position - 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,372 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.nononsenseapps.filepicker;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.FileObserver;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.AsyncTaskLoader;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.util.SortedList;
|
||||
import android.support.v7.widget.util.SortedListAdapterCallback;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* An implementation of the picker which allows you to select a file from the internal/external
|
||||
* storage (SD-card) on a device.
|
||||
*/
|
||||
public abstract class FilePickerFragment extends AbstractFilePickerFragment<File> {
|
||||
|
||||
private static final String[] extensions = new String[]{".doc", ".docx", ".xlsx", ".xls", ".png", ".jpg",
|
||||
".tif", ".tiff", ".pdf", ".jpeg", ".ppt", ".pptx"};
|
||||
|
||||
protected static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
||||
protected boolean showHiddenItems = false;
|
||||
private File mRequestedPath = null;
|
||||
|
||||
/**
|
||||
* This method is used to dictate whether hidden files and folders should be shown or not
|
||||
*
|
||||
* @param showHiddenItems whether hidden items should be shown or not
|
||||
*/
|
||||
public void showHiddenItems(boolean showHiddenItems) {
|
||||
this.showHiddenItems = showHiddenItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if hidden items are shown or not
|
||||
*
|
||||
* @return true if hidden items are shown, otherwise false
|
||||
*/
|
||||
|
||||
public boolean areHiddenItemsShown() {
|
||||
return showHiddenItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if app has been granted permission to write to the SD-card.
|
||||
*/
|
||||
@Override
|
||||
protected boolean hasPermission(@NonNull File path) {
|
||||
return PackageManager.PERMISSION_GRANTED ==
|
||||
ContextCompat.checkSelfPermission(getContext(),
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request permission to write to the SD-card.
|
||||
*/
|
||||
@Override
|
||||
protected void handlePermission(@NonNull File path) {
|
||||
// Should we show an explanation?
|
||||
// if (shouldShowRequestPermissionRationale(
|
||||
// Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// Explain to the user why we need permission
|
||||
// }
|
||||
|
||||
mRequestedPath = path;
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||
PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This the method that gets notified when permission is granted/denied. By default,
|
||||
* a granted request will result in a refresh of the list.
|
||||
*
|
||||
* @param requestCode the code you requested
|
||||
* @param permissions array of permissions you requested. empty if process was cancelled.
|
||||
* @param grantResults results for requests. empty if process was cancelled.
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
@NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
// If arrays are empty, then process was cancelled
|
||||
if (permissions.length == 0) {
|
||||
// Treat this as a cancel press
|
||||
if (mListener != null) {
|
||||
mListener.onCancelled();
|
||||
dismiss();
|
||||
}
|
||||
} else { // if (requestCode == PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE) {
|
||||
if (PackageManager.PERMISSION_GRANTED == grantResults[0]) {
|
||||
// Do refresh
|
||||
if (mRequestedPath != null) {
|
||||
refresh(mRequestedPath);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getContext(), R.string.nnf_permission_external_write_denied,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
// Treat this as a cancel press
|
||||
if (mListener != null) {
|
||||
mListener.onCancelled();
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the path is a directory and not a file.
|
||||
*
|
||||
* @param path either a file or directory
|
||||
* @return true if path is a directory, false if file
|
||||
*/
|
||||
@Override
|
||||
public boolean isDir(@NonNull final File path) {
|
||||
return path.isDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path either a file or directory
|
||||
* @return filename of path
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName(@NonNull File path) {
|
||||
return path.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path to the parent directory. Should return the root if
|
||||
* from is root.
|
||||
*
|
||||
* @param from either a file or directory
|
||||
* @return the parent directory
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public File getParent(@NonNull final File from) {
|
||||
if (from.getPath().equals(getRoot().getPath())) {
|
||||
// Already at root, we can't go higher
|
||||
return from;
|
||||
} else if (from.getParentFile() != null) {
|
||||
return from.getParentFile();
|
||||
} else {
|
||||
return from;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the path to the type used.
|
||||
*
|
||||
* @param path either a file or directory
|
||||
* @return File representation of the string path
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public File getPath(@NonNull final String path) {
|
||||
return new File(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path either a file or directory
|
||||
* @return the full path to the file
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public String getFullPath(@NonNull final File path) {
|
||||
return path.getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root path.
|
||||
*
|
||||
* @return the highest allowed path, which is "/" by default
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public File getRoot() {
|
||||
return new File("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the path to a URI for the return intent
|
||||
*
|
||||
* @param file either a file or directory
|
||||
* @return a Uri
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public Uri toUri(@NonNull final File file) {
|
||||
return Uri.fromFile(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a loader that lists the Files in the current path,
|
||||
* and monitors changes.
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public Loader<SortedList<File>> getLoader() {
|
||||
return new AsyncTaskLoader<SortedList<File>>(getActivity()) {
|
||||
|
||||
FileObserver fileObserver;
|
||||
|
||||
@Override
|
||||
public SortedList<File> loadInBackground() {
|
||||
File[] listFiles = mCurrentPath.listFiles();
|
||||
final int initCap = listFiles == null ? 0 : listFiles.length;
|
||||
|
||||
SortedList<File> files = new SortedList<>(File.class, new SortedListAdapterCallback<File>(getDummyAdapter()) {
|
||||
@Override
|
||||
public int compare(File lhs, File rhs) {
|
||||
return compareFiles(lhs, rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(File file, File file2) {
|
||||
return file.getAbsolutePath().equals(file2.getAbsolutePath()) && (file.isFile() == file2.isFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(File file, File file2) {
|
||||
return areContentsTheSame(file, file2);
|
||||
}
|
||||
}, initCap);
|
||||
|
||||
|
||||
files.beginBatchedUpdates();
|
||||
if (listFiles != null) {
|
||||
for (java.io.File f : listFiles) {
|
||||
if (isItemVisible(f) && directoryHasNeededFiles(f)) {
|
||||
files.add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
files.endBatchedUpdates();
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to start the Loader.
|
||||
*/
|
||||
@Override
|
||||
protected void onStartLoading() {
|
||||
super.onStartLoading();
|
||||
|
||||
// handle if directory does not exist. Fall back to root.
|
||||
if (mCurrentPath == null || !mCurrentPath.isDirectory()) {
|
||||
mCurrentPath = getRoot();
|
||||
}
|
||||
|
||||
// Start watching for changes
|
||||
fileObserver = new FileObserver(mCurrentPath.getPath(),
|
||||
FileObserver.CREATE |
|
||||
FileObserver.DELETE
|
||||
| FileObserver.MOVED_FROM | FileObserver.MOVED_TO
|
||||
) {
|
||||
|
||||
@Override
|
||||
public void onEvent(int event, String path) {
|
||||
// Reload
|
||||
onContentChanged();
|
||||
}
|
||||
};
|
||||
fileObserver.startWatching();
|
||||
|
||||
forceLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to completely reset the Loader.
|
||||
*/
|
||||
@Override
|
||||
protected void onReset() {
|
||||
super.onReset();
|
||||
|
||||
// Stop watching
|
||||
if (fileObserver != null) {
|
||||
fileObserver.stopWatching();
|
||||
fileObserver = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean directoryHasNeededFiles(@NonNull final File file) {
|
||||
final File[] fileList = file.listFiles();
|
||||
if (fileList == null) {
|
||||
return isNeededExtension(file.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isNeededExtension(@NonNull final String fileName) {
|
||||
for (final String extension : extensions) {
|
||||
if (fileName.endsWith(extension) || fileName.endsWith(extension.toUpperCase(Locale.getDefault()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name is validated to be non-null, non-empty and not containing any
|
||||
* slashes.
|
||||
*
|
||||
* @param name The name of the folder the user wishes to create.
|
||||
*/
|
||||
@Override
|
||||
public void onNewFolder(@NonNull final String name) {
|
||||
File folder = new File(mCurrentPath, name);
|
||||
|
||||
if (folder.mkdir()) {
|
||||
refresh(folder);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.nnf_create_folder_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the list to determine whether a file should be displayed or not.
|
||||
* Default behavior is to always display folders. If files can be selected,
|
||||
* then files are also displayed. Set the showHiddenFiles property to show
|
||||
* hidden file. Default behaviour is to hide hidden files. Override this method to enable other
|
||||
* filtering behaviour, like only displaying files with specific extensions (.zip, .txt, etc).
|
||||
*
|
||||
* @param file to maybe add. Can be either a directory or file.
|
||||
* @return True if item should be added to the list, false otherwise
|
||||
*/
|
||||
protected boolean isItemVisible(final File file) {
|
||||
if (!showHiddenItems && file.isHidden()) {
|
||||
return false;
|
||||
}
|
||||
return super.isItemVisible(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two files to determine their relative sort order. This follows the usual
|
||||
* comparison interface. Override to determine your own custom sort order.
|
||||
* <p/>
|
||||
* Default behaviour is to place directories before files, but sort them alphabetically
|
||||
* otherwise.
|
||||
*
|
||||
* @param lhs File on the "left-hand side"
|
||||
* @param rhs File on the "right-hand side"
|
||||
* @return -1 if if lhs should be placed before rhs, 0 if they are equal,
|
||||
* and 1 if rhs should be placed before lhs
|
||||
*/
|
||||
protected int compareFiles(@NonNull File lhs, @NonNull File rhs) {
|
||||
if (lhs.isDirectory() && !rhs.isDirectory()) {
|
||||
return -1;
|
||||
} else if (rhs.isDirectory() && !lhs.isDirectory()) {
|
||||
return 1;
|
||||
} else {
|
||||
return lhs.getName().compareToIgnoreCase(rhs.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.nononsenseapps.filepicker;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.util.SortedList;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* An interface for the methods required to handle backend-specific stuff.
|
||||
*/
|
||||
public interface LogicHandler<T> {
|
||||
|
||||
int VIEWTYPE_HEADER = 0;
|
||||
int VIEWTYPE_DIR = 1;
|
||||
int VIEWTYPE_CHECKABLE = 2;
|
||||
|
||||
/**
|
||||
* Return true if the path is a directory and not a file.
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
boolean isDir(@NonNull final T path);
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return filename of path
|
||||
*/
|
||||
@NonNull
|
||||
String getName(@NonNull final T path);
|
||||
|
||||
/**
|
||||
* Convert the path to a URI for the return intent
|
||||
*
|
||||
* @param path
|
||||
* @return a Uri
|
||||
*/
|
||||
@NonNull
|
||||
Uri toUri(@NonNull final T path);
|
||||
|
||||
/**
|
||||
* Return the path to the parent directory. Should return the root if
|
||||
* from is root.
|
||||
*
|
||||
* @param from
|
||||
*/
|
||||
@NonNull
|
||||
T getParent(@NonNull final T from);
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return the full path to the file
|
||||
*/
|
||||
@NonNull
|
||||
String getFullPath(@NonNull final T path);
|
||||
|
||||
/**
|
||||
* Convert the path to the type used.
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
@NonNull
|
||||
T getPath(@NonNull final String path);
|
||||
|
||||
/**
|
||||
* Get the root path (lowest allowed).
|
||||
*/
|
||||
@NonNull
|
||||
T getRoot();
|
||||
|
||||
/**
|
||||
* Get a loader that lists the files in the current path,
|
||||
* and monitors changes.
|
||||
*/
|
||||
@NonNull
|
||||
Loader<SortedList<T>> getLoader();
|
||||
|
||||
/**
|
||||
* Bind the header ".." which goes to parent folder.
|
||||
*
|
||||
* @param viewHolder
|
||||
*/
|
||||
void onBindHeaderViewHolder(@NonNull AbstractFilePickerFragment<T>.HeaderViewHolder viewHolder);
|
||||
|
||||
/**
|
||||
* Header is subtracted from the position
|
||||
*
|
||||
* @param parent
|
||||
* @param viewType
|
||||
* @return a view holder for a file or directory
|
||||
*/
|
||||
@NonNull
|
||||
RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType);
|
||||
|
||||
/**
|
||||
* @param viewHolder to bind data from either a file or directory
|
||||
* @param position 0 - n, where the header has been subtracted
|
||||
* @param data
|
||||
*/
|
||||
void onBindViewHolder(@NonNull AbstractFilePickerFragment<T>.DirViewHolder viewHolder,
|
||||
int position, @NonNull T data);
|
||||
|
||||
/**
|
||||
* @param position 0 - n, where the header has been subtracted
|
||||
* @param data
|
||||
* @return an integer greater than 0
|
||||
*/
|
||||
int getItemViewType(int position, @NonNull T data);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.nononsenseapps.filepicker;
|
||||
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import static com.nononsenseapps.filepicker.Utils.isValidFileName;
|
||||
|
||||
public class NewFolderFragment extends NewItemFragment {
|
||||
|
||||
private static final String TAG = "new_folder_fragment";
|
||||
|
||||
public static void showDialog(@NonNull final FragmentManager fm,
|
||||
@Nullable final OnNewFolderListener listener) {
|
||||
NewItemFragment d = new NewFolderFragment();
|
||||
d.setListener(listener);
|
||||
d.show(fm, TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateName(@Nullable final String itemName) {
|
||||
return isValidFileName(itemName);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.nononsenseapps.filepicker;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
public abstract class NewItemFragment extends DialogFragment {
|
||||
|
||||
private OnNewFolderListener listener = null;
|
||||
|
||||
public NewItemFragment() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setListener(@Nullable final OnNewFolderListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setView(R.layout.nnf_dialog_folder_name)
|
||||
.setTitle(R.string.nnf_new_folder)
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
null)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
null);
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog1) {
|
||||
final AlertDialog dialog = (AlertDialog) dialog1;
|
||||
final EditText editText = (EditText) dialog.findViewById(R.id.edit_text);
|
||||
|
||||
if (editText == null) {
|
||||
throw new NullPointerException("Could not find an edit text in the dialog");
|
||||
}
|
||||
|
||||
Button cancel = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
final Button ok = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
// Start disabled
|
||||
ok.setEnabled(false);
|
||||
ok.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String itemName = editText.getText().toString();
|
||||
if (validateName(itemName)) {
|
||||
if (listener != null) {
|
||||
listener.onNewFolder(itemName);
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(final CharSequence s, final int start,
|
||||
final int count, final int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(final CharSequence s, final int start,
|
||||
final int before, final int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(final Editable s) {
|
||||
ok.setEnabled(validateName(s.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
protected abstract boolean validateName(final String itemName);
|
||||
|
||||
public interface OnNewFolderListener {
|
||||
void onNewFolder(@NonNull final String name);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.nononsenseapps.filepicker;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
/**
|
||||
* Some utility methods
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
private static final String SEP = "/";
|
||||
|
||||
/**
|
||||
* Name is validated to be non-null, non-empty and not containing any
|
||||
* slashes.
|
||||
*
|
||||
* @param name The name of the folder the user wishes to create.
|
||||
*/
|
||||
public static boolean isValidFileName(@Nullable String name) {
|
||||
return !TextUtils.isEmpty(name)
|
||||
&& !name.contains("/")
|
||||
&& !name.equals(".")
|
||||
&& !name.equals("..");
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the second pathString to the first. The result will not end with a /.
|
||||
* In case two absolute paths are given, e.g. /A/B/, and /C/D/, then the result
|
||||
* will be /A/B/C/D
|
||||
*
|
||||
* Multiple slashes will be shortened to a single slash, so /A///B is equivalent to /A/B
|
||||
*/
|
||||
@NonNull
|
||||
public static String appendPath(@NonNull String first,
|
||||
@NonNull String second) {
|
||||
String result = first + SEP + second;
|
||||
|
||||
while (result.contains("//")) {
|
||||
result = result.replaceAll("//", "/");
|
||||
}
|
||||
|
||||
if (result.length() > 1 && result.endsWith(SEP)) {
|
||||
return result.substring(0, result.length() - 1);
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M20,6h-8l-2,-2L4,4c-1.11,0 -1.99,0.89 -1.99,2L2,18c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,8c0,-1.11 -0.89,-2 -2,-2zM19,14h-3v3h-2v-3h-3v-2h3L14,9h2v3h3v2z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/fragment"
|
||||
android:layout_gravity="center"/>
|
||||
</merge>
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_text"
|
||||
style="?android:textAppearanceMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:fontFamily="light"
|
||||
android:maxLines="1"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="@string/nnf_name"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textAutoComplete|textAutoCorrect"
|
||||
android:padding="4dp"
|
||||
tools:ignore="UnusedAttribute"/>
|
||||
</FrameLayout>
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
<LinearLayout android:id="@+id/nnf_item_container"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:listPreferredItemHeight"
|
||||
android:background="?selectableItemBackground"
|
||||
android:focusable="true"
|
||||
android:minHeight="?android:listPreferredItemHeight"
|
||||
android:nextFocusLeft="@+id/nnf_button_cancel"
|
||||
android:nextFocusRight="@id/checkbox"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
<!--suppress AndroidDomInspection -->
|
||||
<ImageView
|
||||
android:id="@+id/item_icon"
|
||||
android:layout_width="?android:listPreferredItemHeight"
|
||||
android:layout_height="?android:listPreferredItemHeight"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/nnf_ic_folder_black_48dp"
|
||||
android:tint="?attr/nnf_dir_icon_color"
|
||||
android:visibility="visible"
|
||||
tools:ignore="ContentDescription,VectorDrawableCompat" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/text1"
|
||||
style="?android:textAppearanceLarge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="@android:color/black"
|
||||
android:maxLines="1"
|
||||
android:padding="8dp"
|
||||
android:text="@string/nnf_name" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:nextFocusLeft="@id/nnf_item_container"
|
||||
android:nextFocusRight="@+id/nnf_button_ok"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingRight="8dp"
|
||||
tools:ignore="RtlSymmetry"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
<LinearLayout android:id="@+id/nnf_item_container"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:listPreferredItemHeight"
|
||||
android:background="?selectableItemBackground"
|
||||
android:focusable="true"
|
||||
android:minHeight="?android:listPreferredItemHeight"
|
||||
android:nextFocusLeft="@+id/nnf_button_cancel"
|
||||
android:nextFocusRight="@+id/nnf_button_ok"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!--suppress AndroidDomInspection -->
|
||||
<ImageView
|
||||
android:id="@+id/item_icon"
|
||||
android:layout_width="?android:listPreferredItemHeight"
|
||||
android:layout_height="?android:listPreferredItemHeight"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/nnf_ic_folder_black_48dp"
|
||||
android:tint="?attr/nnf_dir_icon_color"
|
||||
android:visibility="visible"
|
||||
tools:ignore="ContentDescription,VectorDrawableCompat"/>
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/text1"
|
||||
style="?android:textAppearanceLarge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="8dp"
|
||||
android:text="@string/nnf_name"
|
||||
android:textColor="@android:color/white"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/nnf_picker_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="?nnf_toolbarTheme">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nnf_current_dir"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="start"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
tools:ignore="Deprecated"/>
|
||||
<!--
|
||||
suppressing deprecation of singleLine to fix crash related to ellipsize="start", see bug:
|
||||
https://issuetracker.google.com/issues/36950033
|
||||
-->
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@+id/nnf_buttons_container"
|
||||
android:layout_below="@+id/nnf_picker_toolbar"
|
||||
android:descendantFocusability="afterDescendants"
|
||||
android:focusable="true"
|
||||
tools:listitem="@layout/nnf_filepicker_listitem_dir"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/nnf_buttons_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/nnf_button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/nnf_button_cancel"
|
||||
style="?attr/borderlessButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/cancel"
|
||||
android:textColor="@android:color/white"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/nnf_button_ok"
|
||||
style="?attr/borderlessButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/ok"
|
||||
android:textColor="@android:color/white"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/nnf_newfile_button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/nnf_text_filename"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/nnf_filename"
|
||||
android:maxLines="1"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/nnf_button_ok_newfile"
|
||||
style="?attr/borderlessButtonStyle"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:hint="@android:string/ok"
|
||||
android:src="@drawable/nnf_ic_save_black_24dp"
|
||||
android:tint="?attr/nnf_save_icon_color"
|
||||
tools:ignore="VectorDrawableCompat"/>
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_above="@id/nnf_buttons_container"
|
||||
android:background="?nnf_separator_color"/>
|
||||
</RelativeLayout>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/nnf_action_createdir"
|
||||
android:title="@string/nnf_new_folder"
|
||||
app:showAsAction="always"
|
||||
android:orderInCategory="1"
|
||||
android:icon="@drawable/nnf_ic_create_new_folder_white_24dp"
|
||||
/>
|
||||
</menu>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ This Source Code Form is subject to the terms of the Mozilla Public
|
||||
~ License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
~ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<!-- Specifies theme to apply to the toolbar -->
|
||||
<attr name="nnf_toolbarTheme" format="reference"/>
|
||||
<!-- Color to apply to separator for OK/Cancel buttons -->
|
||||
<attr name="nnf_separator_color" format="color"/>
|
||||
<!-- Color to apply to the save icon -->
|
||||
<attr name="nnf_save_icon_color" format="color"/>
|
||||
<!-- Color to apply to the directory icons in list -->
|
||||
<attr name="nnf_dir_icon_color" format="color"/>
|
||||
<!-- Drawable to use as a divider between list items (optional) -->
|
||||
<attr name="nnf_list_item_divider" format="reference"/>
|
||||
</resources>
|
||||