• Stars
    star
    514
  • Rank 82,742 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A directory chooser library for Android.

Android DirectoryChooser

Build Status Gittip Maven Central Stories in Ready Android Arsenal

A simple directory chooser you can integrate into your Android app.

This version of the library has no additional dependencies, but requires Android v11+ to work. There is, however, a pre-v11-branch that supports down to v7 using ActionBarSherlock.

You can download the sample app from the Play Store:

Get it on Google Play

Based on the DirectoryChooser from the excellent AntennaPod App by danieloeh.

As stand-alone Activity
As DialogFragment

Usage

For a full example see the sample app in the repository.

From Maven Central

Library releases are available on Maven Central, snapshots can be retrieved from Sonatype:

Release (SDK 11+)

Gradle

compile 'net.rdrei.android.dirchooser:library:3.2@aar'

Maven

<dependency>
  <groupId>net.rdrei.android.dirchooser</groupId>
  <artifactId>library</artifactId>
  <version>3.2</version>
  <type>aar</type>
</dependency>

Release (SDK 7+)

Gradle

compile 'net.rdrei.android.dirchooser:library:1.0-pre-v11@aar'

Maven

<dependency>
  <groupId>net.rdrei.android.dirchooser</groupId>
  <artifactId>library</artifactId>
  <version>1.0-pre-v11</version>
  <type>aar</type>
</dependency>

Snapshot (SDK 11+)

compile 'net.rdrei.android.dirchooser:library:3.2-SNAPSHOT@aar'

Snapshot (SDK 4+)

compile 'net.rdrei.android.dirchooser:library:2.0-pre-v11-SNAPSHOT@aar'

As Library Project

Alternatively, check out this repository and add it as a library project.

$ git clone https://github.com/passy/Android-DirectoryChooser.git

Import the project into your favorite IDE and add android.library.reference.1=/path/to/Android-DirectoryChooser/library to your project.properties.

Manifest

You need to declare the DirectoryChooserActivity and request the android.permission.WRITE_EXTERNAL_STORAGE permission.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
<application>
    <activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" />
</application>

Activity

To choose a directory, start the activity from your app logic:

final Intent chooserIntent = new Intent(this, DirectoryChooserActivity.class);

final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
        .newDirectoryName("DirChooserSample")
        .allowReadOnlyDirectory(true)
        .allowNewDirectoryNameModification(true)
        .build();

chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config);

// REQUEST_DIRECTORY is a constant integer to identify the request, e.g. 0
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);

Handle the result in your onActivityResult method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_DIRECTORY) {
        if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
            handleDirectoryChoice(data
                .getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR));
        } else {
            // Nothing selected
        }
    }
}

Fragment

You can also use the underlying DialogFragment for even better integration. Whether you use the Fragment as a Dialog or not is completely up to you. All you have to do is implement the OnFragmentInteractionListener interface to respond to the events that a directory is selected or the user cancels the dialog:

public class DirChooserFragmentSample extends Activity implements
    DirectoryChooserFragment.OnFragmentInteractionListener {

    private TextView mDirectoryTextView;
    private DirectoryChooserFragment mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog);
        final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
                .newDirectoryName("DialogSample")
                .build();
        mDialog = DirectoryChooserFragment.newInstance(config);

        mDirectoryTextView = (TextView) findViewById(R.id.textDirectory);

        findViewById(R.id.btnChoose)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mDialog.show(getFragmentManager(), null);
                    }
                });
    }

    @Override
    public void onSelectDirectory(@NonNull String path) {
        mDirectoryTextView.setText(path);
        mDialog.dismiss();
    }

    @Override
    public void onCancelChooser() {
        mDialog.dismiss();
    }
}

If calling the directory chooser from your own fragment, be sure to set the target fragment first:

@Override
public void onClick(View v) {
    mDialog.setTargetFragment(this, 0);
    mDialog.show(getFragmentManager(), null);
}

Configuration

The Directory Chooser is configured through a parcelable configuration object, which is great because it means that you don't have to tear your hair out over finicky string extras. Instead, you get auto-completion and a nice immutable data structure. Here's what you can configure:

newDirectoryName : String (required)

Name of the directory to create. User can change this name when he creates the folder. To avoid this use allowNewDirectoryNameModification argument.

initialDirectory : String (default: "")

Optional argument to define the path of the directory that will be shown first. If it is not sent or if path denotes a non readable/writable directory or it is not a directory, it defaults to android.os.Environment#getExternalStorageDirectory().

allowReadOnlyDirectory : Boolean (default: false)

Argument to define whether or not the directory chooser allows read-only paths to be chosen. If it false only directories with read-write access can be chosen.

allowNewDirectoryNameModification : Boolean (default: false)

Argument to define whether or not the directory chooser allows modification of provided new directory name.

Example

final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
        .newDirectoryName("DialogSample")
        .allowNewDirectoryNameModification(true)
        .allowReadOnlyDirectory(true)
        .initialDirectory("/sdcard")
        .build();

Apps using this

Popcorn Time for Android
Popcorn Time for Android
Emby for Android
Emby for Android
Downloader for SoundCloud
Downloader for SoundCloud
Wallpaper Changer
Wallpaper Changer
XnRetro
XnRetro
InstaSave - Instagram Save
InstaSave
ML Manager - App manager
ML Manager
AutoGuard - Dash Cam
AutoGuard
Companion for Band
Companion for Band
Swallow Server
Swallow Server
Photo Map
Photo Map

To add your own app, please send a pull request.

Releasing

Preparation

To release a new snapshot on Maven Central, add your credentials to ~/.gradle/gradle.properties (you get them from http://oss.sonatype.org) as well as your signing GPG key:

signing.keyId=0x18EEA4AF
signing.secretKeyRingFile=/home/pascal/.gnupg/secring.gpg

NEXUS_USERNAME=username
NEXUS_PASSWORD=password

Staging

To upload a new snapshot, just run gradle's uploadArchives command:

gradle :library:uploadArchives

Release

Update versions and remove -SNAPSHOT suffixes.

gradle build :library:uploadArchives

License

Copyright 2013-2016 Pascal Hartig

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Thanks

Sample App icon by Frank Souza.

More Repositories

1

build-time-tracker-plugin

Gradle plugin to continuously track and report your build times
Groovy
1,203
star
2

awesome-recursion-schemes

Resources for learning and using recursion schemes.
1,183
star
3

angular-masonry

An AngularJS directive for Masonry.
CoffeeScript
1,118
star
4

awesome-purescript

A curation of awesome PureScript libraries, resources and shiny things.
447
star
5

scdl

Soundcloud Downloader App for Android
Java
301
star
6

givegif

GIFs on the command line
Haskell
220
star
7

autoprefixer-loader

Webpack loader for autoprefixer
JavaScript
217
star
8

android-lint-summary

Prettier display of Android Lint issues
Haskell
178
star
9

x-pokemon

A web component to display Pokémon.
HTML
89
star
10

google-cdn

Replaces references to resources on the Google CDN
JavaScript
70
star
11

react-pokemon

A React component for displaying Pokémon
HTML
58
star
12

generator-heroku

A Heroku config generator for Yeoman
JavaScript
45
star
13

angular-google-staticmaps

An AngularJS directive to quickly insert Google Static Maps.
CoffeeScript
38
star
14

raspbian-vpn-router

Setting up a Raspberry Pi 3 as a VPN Gateway
Shell
33
star
15

generator-bookmarklet

Yeoman Generator for Bookmarklets
JavaScript
33
star
16

ama

Ask Me Anything
33
star
17

flask-gae-mini-profiler

Flask extension for easy profiling on Google App Engine
Python
33
star
18

elm-pokemon

Elm
28
star
19

giphy-api

Giphy HTTP API Wrapper for Haskell
Haskell
27
star
20

ctlmngr

A manager for custom timelines
JavaScript
21
star
21

ltxbot

A Twitter bot that renders LaTeX for you
Haskell
21
star
22

sindrebday

Sindre has circled around the sun once more
HTML
18
star
23

rss-markdown-proxy

A reverse proxy for rendering Markdown within RSS feeds
Haskell
18
star
24

nose-notify

Desktop notifications via notify-osd for nose tests
Python
16
star
25

coding-puzzles

Some public coding puzzles
Haskell
15
star
26

node-dom-urls

A partial implementation of the W3C URL Spec Draft for Node
JavaScript
15
star
27

purescript-errors

Handy error handling combinators for PureScript
PureScript
15
star
28

tweetdock

An experiment architecting something like TweetDeck with Flight.
JavaScript
15
star
29

revmenu

Navigate to git/hg revisions in your terminal using your keyboard.
Rust
12
star
30

cows-hs

ASCII 🐮s
Haskell
12
star
31

latest-npm-version

Get the latest version of a package on npm
Haskell
12
star
32

attic-schedule

A Turtle script I use to kick off attic
Haskell
11
star
33

Horse.hs

Tweet like a Horse
Haskell
10
star
34

podserve

Serve a podcast feed from a directory with MP3s in it.
Rust
10
star
35

passy.me

My homepage
JavaScript
10
star
36

financius-notebook

An IPython Notebook I use to crunch my Financius data
Jupyter Notebook
8
star
37

nose-lettuce

A probably bad idea of how to run lettuce from nose
Python
8
star
38

blog

Articles I've written
7
star
39

Android-ViewPagerIndicator-AAR

AAR fork of Jake Wharton's ViewPagerIndicator
Java
7
star
40

firebase-functions-webpack-example

Firebase Cloud Functions + TypeScript + PureScript + Webpack
JavaScript
7
star
41

purescript-simple-moment

A minimal PureScript wrapper around moment.js
PureScript
7
star
42

hls-proxy

A reverse HTTP proxy that may eventually do things
Haskell
6
star
43

optparse-text

Helpers for optparse-applicative to deal with Data.Text
Haskell
6
star
44

flight-knockout

Easy data-bindings in Flight with Knockout
JavaScript
6
star
45

rust-tracerayer

A toy ray tracer in Rust.
Rust
6
star
46

twentiment

Research project on sentiment analysis using the Naïve Bayes Classificator
Python
6
star
47

absshadow-sample

Sample Android project showing how to test ActionBarSherlock with Robolectric
Java
6
star
48

Android-LintSummarySample

Example of how to use android-lint-summary with gradle
Java
6
star
49

collab-counter

A distributed, eventually consistent counter with magical powers
Elm
5
star
50

backbone.datalink

Wrapper around Synapse for easy data binding between models and views.
CoffeeScript
5
star
51

tube-roundel

Web service for rendering TfL Tube roundels.
Haskell
5
star
52

tweetproxy

An authenticated Twitter API proxy in Haskell. (WIP)
Haskell
5
star
53

twoxpy

A super limited Twitter API OAuth signing proxy
Python
5
star
54

glashammer-rdrei

Fork of Glashammer adding some custom patches
Python
5
star
55

simstatus

Android Application to check for the Sim City Server Status
Java
5
star
56

r3bb

A (really) tiny jQuery based WYSIWYG editor that outputs bbcode
JavaScript
4
star
57

soccer-stats-backend

Backend for my soccer prediction app doing some calculations with NumPy
Python
4
star
58

raspbian-home-server

Shell
4
star
59

todomvc-purescript-react

Nothing to see here, move along!
PureScript
4
star
60

angular-dart-todomvc

Work in progress
Dart
4
star
61

rdreiflask

My old flask-based homepage. No longer under development or in use.
JavaScript
4
star
62

OfflineArticles

[WIP] Offline reading app for Android
HTML
4
star
63

giflib

A PureScript experiment that is supposed to be a personal gif library
PureScript
4
star
64

raspbian-ipv6-router

A Raspberry Pi config to use it as DHCP/RA server
Shell
4
star
65

tube-trains-bot

A Google Home action allowing you to ask for TfL Tube departures.
Haskell
4
star
66

peano

Basic Peano numbers in Haskell
Haskell
4
star
67

playground

Everyone likes to play.
HTML
4
star
68

carbon-intensity-bot

A Google Home bot to enquire about your local electricity's carbon intensity.
TypeScript
4
star
69

simpledownloader

Playground for mono and gtk#
C#
3
star
70

html-oust

[WIP] Extract paths of stylesheets, scripts and HTML imports from HTML files
Haskell
3
star
71

mobile-restaurants

Mobile website prototypes for restaurants build with AngularJS and Yeoman.
JavaScript
3
star
72

dotvim

My neovim configuration
Vim Script
3
star
73

rdreilib

Various reusable utilities for Glashammer/WSGI projects. BSD-licensed.
Python
3
star
74

ics-notebook

A Jupyter notebook for analyzing iCalendar files
Jupyter Notebook
3
star
75

bouncyball

OpenGL bouncing ball with Yampa, GLUT
Haskell
3
star
76

mycdb

Learning project re-implementing a client to read constant databases (CDBs)
C
3
star
77

wakivote

WAKiVote
JavaScript
3
star
78

tube-bot

Messenger bot frontend for the Tube disruption tracker
PureScript
2
star
79

ordered-jobs-kata-rust

Ordered Jobs Kata in Rust
Rust
2
star
80

ConnectivityAlert

Dagger 2 + Android playground
Java
2
star
81

lens-over-tea

Haskell
2
star
82

flight-view-demos

Experiments for combining FlightJS with 2-way data binding libraries
JavaScript
2
star
83

canjs-localstorage

Bower repository of the localStorage plugin for CanJS
JavaScript
2
star
84

java-repl

java-repl for docker
2
star
85

disruption-tracker

Tracking Tube disruptions and write them to a RethinkDB
Haskell
2
star
86

financius2bluecoins

A script to migrate Financius transactions to Bluecoins
Haskell
2
star
87

soccer-stats-frontend

AngularJS-based frontend doing some soccer predictions based on simple time-independent least square regression.
CSS
2
star
88

gymahz_scripts

Scripts for the daily use at the Gymnasium Altenholz
Python
2
star
89

twime

Twitter bot in Scala
Scala
2
star
90

fakemvc

Experimenting with TodoMVC
JavaScript
2
star
91

Android-AdapterMergeExample

Android example for merging multiple adapters for one autocomplete field
Java
2
star
92

gbridge-bridge

Relay gbridge.io events to another MQTT broker. Part of my home IoT setup, but unlikely of any use to anybody else.
Rust
2
star
93

TrieSuggest

Toy program in Haskell using tries to implement some autocompletion stuff
Haskell
2
star
94

WAKiMail

Android mail client for WAK students (www.wak-sh.de)
Java
1
star
95

displaypower

Fun project enabling DPMS when gnome-screensaver turns on
C
1
star
96

photo-share

An Effective Kotlin Android App experiment
Java
1
star
97

twentiment-api

A REST-ish API for twentiment
Python
1
star
98

fun-hs

My attempt to implement @sdiehl's fun language.
Haskell
1
star
99

angularjs-bcki-slides

German slides for my AngularJS session at Barcamp Kiel 2012
JavaScript
1
star
100

level8

My script for cracking Level 8 of the Stripe-CTF challenge
Python
1
star