GithubHelp home page GithubHelp logo

android-directorychooser's Introduction

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.

android-directorychooser's People

Contributors

adithya321 avatar arturdryomov avatar avinash-bhat avatar braisgabin avatar dennyweinberg avatar guicamest avatar harri35 avatar hey-o avatar j4velin avatar jaredsburrows avatar javiersantos avatar klemens avatar majeurandroid avatar maurosoft1973 avatar mdxdave avatar mendhak avatar mfonville avatar mursts avatar newfred avatar oopman avatar parkerk avatar passy avatar pylersm avatar sdabhi23 avatar sindresorhus avatar unifylog avatar urunimi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-directorychooser's Issues

Material Design + Button

Since this library is used by a lot of projects, a material design "new folder" button would be great

Set initial directory - Feature request

Hey, it'd be nice to have the activity receive a string extra in the intent to indicate what directory to show initially (instead of Environment.getExternalStorageDirectory())

I was thinking something like this:

String initialDirectoryPath = getIntent().getStringExtra(EXTRA_INITIAL_DIRECTORY);
File initialDir = (initialDirectoryPath != null && isValidFile(new File(initialDirectoryPath))) ? new File(initialDirectoryPath) : Environment.getExternalStorageDirectory();

    changeDirectory(initialDir);

Could not find com.gu:option:1.3.

Based off #86, since I can't use @aar, I am using compile 'net.rdrei.android.dirchooser:library:3.2' without the @aar. I get the following error, see guardian/Option#2:

$ gradle runDebug
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project '<>'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
   > Could not find com.gu:option:1.3.
     Searched in the following locations:
         https://plugins.gradle.org/m2/com/gu/option/1.3/option-1.3.pom
         https://plugins.gradle.org/m2/com/gu/option/1.3/option-1.3.jar
         https://jitpack.io/com/gu/option/1.3/option-1.3.pom
         https://jitpack.io/com/gu/option/1.3/option-1.3.jar
         file:/<>/.m2/repository/com/gu/option/1.3/option-1.3.pom
         file:/<>/.m2/repository/com/gu/option/1.3/option-1.3.jar
         file:/<>/android-sdk/extras/android/m2repository/com/gu/option/1.3/option-1.3.pom
         file:/<>/android-sdk/extras/android/m2repository/com/gu/option/1.3/option-1.3.jar
         file:/<>/android-sdk/extras/google/m2repository/com/gu/option/1.3/option-1.3.pom
         file:/<>/android-sdk/extras/google/m2repository/com/gu/option/1.3/option-1.3.jar
     Required by:
         :<>:unspecified > net.rdrei.android.dirchooser:library:3.2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.188 secs

I am forced to add maven { url 'http://guardian.github.com/maven/repo-releases' } in repositories.

Unable to navigate higher than root directory of internal storage

This issue exists on my Moto X Play running Android 6.0, specifically in the Snapprefs xposed module (http://forum.xda-developers.com/xposed/modules/app-snapprefs-ultimate-snapchat-utility-t2947254).

Clicking the "up" button while at the internal storage root directory does not advance any further up. I was attempting to access a folder on the SD card. Other apps have no issue reading, writing, or accessing the SD card, so I doubt the problem relates to read/write permissions.

The developer (MaaarZ) said he cannot fix it as the library isn't written by him and suggested I ask you.

Any help would be appreciated, thanks.

Do I include the full Apache License?

Do I have to include the full Apache License in my finale apk? or can I make a activity where it has the Apache License? Can I just include the short version thats in the readme?

Proguard rules

I am seeing hundreds of lines of warnings and errors with proguard. I didnt see this with version 2.1:

Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.tools.Diagnostic$Kind
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.tools.Diagnostic
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.tools.Diagnostic$Kind
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.annotation.processing.Messager
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.annotation.processing.Messager
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.Element
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack$SourcePropertyOrderer: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack$SourcePropertyOrderer: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack$SourcePropertyOrderer: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack$SourcePropertyOrderer: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack$SourcePropertyOrderer: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.EclipseHack$SourcePropertyOrderer: can't find referenced class javax.lang.model.element.TypeElement
Warning: com.google.auto.value.processor.ErrorReporter: can't find referenced class javax.tools.Diagnostic$Kind
Warning: com.google.auto.value.processor.ErrorReporter: can't find referenced class javax.tools.Diagnostic
Warning: com.google.auto.value.processor.ErrorReporter: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning: com.google.auto.value.processor.ErrorReporter: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning: com.google.auto.value.processor.ErrorReporter: can't find referenced class javax.tools.Diagnostic$Kind
Warning: com.google.auto.value.processor.ErrorReporter: can't find referenced class javax.annotation.processing.Messager
Warning: com.google.auto.value.processor.ErrorReporter: can't find referenced class javax.annotation.processing.Messager

Missing artifact (maven dependency)

Hello,
I tried including this library as a Maven dependency but I get a missing artifact error. Both for 1.0-pre-v11 and 2.0.
I'm using the pom.xml snippets provided on the project front page.
Any ideas?
Do I need to add a specific repository perhaps?

onAttach not reattaching listener when screen orientation changes

Hi,
I just made a github account to report this issue. It can be easily reproduced.

  1. Make sure screen rotation is enabled
  2. Open directory chooser
  3. Rotate screen
  4. Tap the bottom buttons - they stopped working
    From my investigation, when screen is rotated. onDetach is called and then onAttach again. But Option.some() call returns None for some reason. So the listeners attached to the buttons stop working.
    I am a noob in android programming so I cannot fix it myself. Otherwise I would be kind enough to submit a pull request.
    FYI, I am using it in fragment mode.

Error

Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment$10: can't find superclass or interface com.gu.option.UnitFunction
Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment$11: can't find superclass or interface com.gu.option.UnitFunction
Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment$2$1: can't find superclass or interface com.gu.option.UnitFunction
Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment: can't find referenced class com.gu.option.Option
Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment$10: can't find referenced class com.gu.option.UnitFunction
Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment$11: can't find referenced class com.gu.option.UnitFunction
Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment$2: can't find referenced class com.gu.option.Option
Warning:net.rdrei.android.dirchooser.DirectoryChooserFragment$2$1: can't find referenced class com.gu.option.UnitFunction
Warning:there were 20 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
:app:proguardDebug FAILED
Error:Execution failed for task ':app:proguardDebug'.

java.io.IOException: Please correct the above warnings first.

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/gu/option/Option;

When using compile 'net.rdrei.android.dirchooser:library:3.2@aar', I get the following error:

04-09 22:50:20.638 11862 11862 E AndroidRuntime: Process: <>, PID: 11862
04-09 22:50:20.638 11862 11862 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/gu/option/Option;
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at net.rdrei.android.dirchooser.DirectoryChooserFragment.<init>(DirectoryChooserFragment.java:61)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at net.rdrei.android.dirchooser.DirectoryChooserFragment.newInstance(DirectoryChooserFragment.java:91)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at net.rdrei.android.dirchooser.DirectoryChooserActivity.onCreate(DirectoryChooserActivity.java:38)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:6570)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2641)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.app.ActivityThread.-wrap12(ActivityThread.java)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5849)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:763)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)
04-09 22:50:20.638 11862 11862 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gu.option.Option" on path: DexPathList[[zip file "/data/app/<>-2/base.apk"],nativeLibraryDirectories=[/data/app/<>-2/lib/arm, /system/lib, /vendor/lib]]
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:94)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:311)
04-09 22:50:20.638 11862 11862 E AndroidRuntime:    ... 15 more
04-09 22:50:20.641 23023 23744 W ActivityManager:   Force finishing activity <>/net.rdrei.android.dirchooser.DirectoryChooserActivity

I have to use compile 'net.rdrei.android.dirchooser:library:3.2 instead.

Modifying behaviour

Hi, I'm pretty new at Android developing (and Java for that matter) but i'm using you directory chooser in my app and I would like to modify the behaviour of the directory chooser so that
a.- Doesn't show the hidden files (starting with . (dot)) and;
b.- Doesn't show the add folder option.

Is there any way to do this without modifying the library source code (by overriding methods or something similar)?

Thanks in advance!

NPE net.rdrei.android.dirchooser.DirectoryChooserFragment.onSaveInstanceState:103

java.lang.NullPointerException
       at net.rdrei.android.dirchooser.DirectoryChooserFragment.onSaveInstanceState(DirectoryChooserFragment.java:103)
       at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:1647)
       at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1610)
       at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1678)
       at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:546)
       at android.app.Activity.performSaveInstanceState(Activity.java:1157)
       at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1287)
       at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3211)
       at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3269)
       at android.app.ActivityThread.access$900(ActivityThread.java:139)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:156)
       at android.app.ActivityThread.main(ActivityThread.java:4977)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
       at dalvik.system.NativeStart.main(NativeStart.java)

allow a way to track the directory chooser

If there are different directory chooser used in an activity, then there is no way to tell which file chooser is calling in the callbacks, which is forced upon the Activity to implement.

one way to counter this is to allow setting the listener to anything other than activity, and let the users take care of the configuration changes to set the listener back to what it was before the change.

Gradle build fails: "Failed to resolve: com.gu:option:1.3"

The build with gradle in Android studio fails for me with the following error message:

Error:Failed to resolve: com.gu:option:1.3

It looks like the corresponding page in the maven repository is offline: http://mvnrepository.com/artifact/com.gu/option

This is what my build.gradle looks like:

repositories {
mavenCentral()
jcenter()
maven {
url "https://jitpack.io"
}
}

dependencies {
[...]
compile 'com.github.passy:Android-DirectoryChooser:v3.1'
}

java.lang.IllegalStateException: Fragment already added: DirectoryFragment{4280c6d8 #3}

http://crashes.to/s/98c7b844116

java.lang.IllegalStateException: Fragment already added: DirectoryFragment{4280c6d8 #3}
       at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1175)
       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:616)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
       at android.os.Handler.handleCallback(Handler.java:615)
       at android.os.Handler.dispatchMessage(Handler.java:92)
       at android.os.Looper.loop(Looper.java:153)
       at android.app.ActivityThread.main(ActivityThread.java:5000)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
       at dalvik.system.NativeStart.main(NativeStart.java)

Revive pre-v11 version

Since I personally don't support Android < 4.0 in my projects anymore, the recent refactor relies on "native" Fragments and the ActionBar. However, it should be fairly straightforward to use the support library and ActionBarCompat.

If someone wants to pick this up, feel free to!

Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:18:5-65:19 to override.

When using compile 'net.rdrei.android.dirchooser:library:3.2@aar', remove the theme in the application manifest. Only use theme for the activity.

:processDebugManifest
/<>/AndroidManifest.xml:21:9-40 Error:
    Attribute application@theme value=(@style/AppTheme) from AndroidManifest.xml:21:9-40
    is also present at [net.rdrei.android.dirchooser:library:3.2] AndroidManifest.xml:9:18-62 value=(@style/DirectoryChooserTheme).
    Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:18:5-65:19 to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

:processDebugManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugManifest'.
> Manifest merger failed : Attribute application@theme value=(@style/AppTheme) from AndroidManifest.xml:21:9-40
    is also present at [net.rdrei.android.dirchooser:library:3.2] AndroidManifest.xml:9:18-62 value=(@style/DirectoryChooserTheme).
    Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:18:5-65:19 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 0.8 secs

Fragment use: You must provide EXTRA_CONFIG when starting the DirectoryChooserActivity

I am using the dirchooser in Fragment mode and every so often I get crash reports originating form the IllegalArgumentException "You must provide EXTRA_CONFIG when starting the DirectoryChooserActivity". That exception is only thrown in the Activity version and I cannot for the life of me figure out how that gets involved in he process. The crash reports do tend to come from devices with tiny screens like the Defy Mini XT320 on older Android versions, but I am stumped how to solve this.

My calling code looks like this:

public void setDownloadFolder(@SuppressWarnings("UnusedParameters") @Nullable View view){
        if(!Globals.PERMISSION_STORAGE){
            // this just makes sure the permission is requested and this method
            // called again with the same parameters if granted
            requestStoragePermissions(this, "setDownloadFolder", new Object[]{null});
            return;
        }

        final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
                .newDirectoryName("EBooks")
                .initialDirectory(settings.getString(Globals.DOWNLOAD_DIR,
                        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()))
                .allowNewDirectoryNameModification(true)
                .allowReadOnlyDirectory(false)
                .build();
        mDialog = DirectoryChooserFragment.newInstance(config);
        mDialog.show(getFragmentManager(), null);
}

EDIT: I am using version 3.2 of the library

pre-v11 not found

Hi,
I want to use pre-v11 version of this lib.
I have a problem with my gradle sync:

Error:Artifact 'library.aar (net.rdrei.android.dirchooser:library:1.0-pre-v11)' not found.
Searched in the following locations:
    https://jcenter.bintray.com/net/rdrei/android/dirchooser/library/1.0-pre-v11/library-1.0-pre-v11.aar

When I put gradle link to normal version (11+) it works fine.

Upgrade toolchain

There are a lot of outdated packages. Let's bring it up do date, with the exception of the support lib, though, as it seems to have some weirdnesses in 21+.

No + button when using activity in version 2.1

When the DirectoryChooserActivity is used, the +_button to add a new directory is not shown. But the activity requires the EXTRA_NEW_DIR_NAME intent extra to be set, otherwise it results in exceptions. I think the code responsible for this might be the following from DirectoryChooserFragment:202-204:

if (!getShowsDialog()) {
mBtnCreateFolder.setVisibility(View.GONE);
}
I.e. if the fragment is not shown as a dialog, the create folder button is hidden.

Am I missing something, or is there another way to create the folder using activity or non-dialog fragment?

NoClassDefFoundError exception

This happens when pressing the button with the Intent.

final Intent chooserIntent = new Intent(context, DirectoryChooserActivity.class);
final DirectoryChooserConfig chooserConfig = DirectoryChooserConfig.builder()
         .newDirectoryName("Dir")
         .allowReadOnlyDirectory(false)
         .allowNewDirectoryNameModification(true)
         .build();
chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, chooserConfig);
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);

Logcat:

08-18 17:43:11.354  27433-27433/com.javiersantos.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.javiersantos.myapp, PID: 27433
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/gu/option/Option;
            at net.rdrei.android.dirchooser.DirectoryChooserFragment.<init>(DirectoryChooserFragment.java:60)
            at net.rdrei.android.dirchooser.DirectoryChooserFragment.newInstance(DirectoryChooserFragment.java:90)
            at net.rdrei.android.dirchooser.DirectoryChooserActivity.onCreate(DirectoryChooserActivity.java:38)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
            at android.app.ActivityThread.access$900(ActivityThread.java:154)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5289)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gu.option.Option" on path: DexPathList[[zip file "/data/app/com.javiersantos.myapp-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at net.rdrei.android.dirchooser.DirectoryChooserFragment.<init>(DirectoryChooserFragment.java:60)
            at net.rdrei.android.dirchooser.DirectoryChooserFragment.newInstance(DirectoryChooserFragment.java:90)
            at net.rdrei.android.dirchooser.DirectoryChooserActivity.onCreate(DirectoryChooserActivity.java:38)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
            at android.app.ActivityThread.access$900(ActivityThread.java:154)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5289)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
    Suppressed: java.lang.ClassNotFoundException: com.gu.option.Option
            at java.lang.Class.classForName(Native Method)
            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 17 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Theme used in the library conflicts with others

If you use this library you get an error that the app theme is already defined (in my own project). To fix this, you can for example add tools:replace="android:icon, android:label, android:theme, android:name" in your application tag in the manifest. However, this causes instability with other libraries such as com.daimajia.slider:library:1.1.5.

Giving the error

Caused by: android.view.InflateException: Binary XML file line #83: Error inflating class com.daimajia.slider.library.SliderLayout

Is there a way to make them all work happily together?

Publish AAR package

Should also be ported to gradle for this, including the example. Could be fun!

The TextView mTxtvSelectedFolder seems not to be populated.

Hi! @passy

I'm trying to use the library (2.1 version).

All went OK but I'm hitting the following problem: The TextView showing the selected folder is not been populated and refreshed on my app.
Could this be because my theme is not the native Holo? I'm using the AppCompat theme to support legacy Android versions.

android:theme="@style/Theme.AppCompat"

Or maybe it is populated but because I'm using a dark AppCompat theme the text is there but not passed to light color?

Thanks for any advice you could give to me.
Martin

Error

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute application@theme value=(@style/AppTheme) from AndroidManifest.xml:18:9
is also present at net.rdrei.android.dirchooser:library:3.2:9:18 value=(@style/DirectoryChooserTheme)
Suggestion: add 'tools:replace="android:theme"' to element at AndroidManifest.xml:14:5 to override

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.