DirectoryChooser

November 18, 2015 0 Comments

Directory chooser and Folder chooser Dailoge no need of intent call.

So Used this Code : DirectoryChooser

Gradle :
compile 'net.rdrei.android.dirchooser:library:3.0@aar'

Maven

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


Manifest


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


Activity


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);



=============== ++++ On Activity Result ========================


@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


++++++++++++
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();
}
}

Example


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

Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Popular Posts