Disable 'confirm' button if selected folder isn't valid

This commit is contained in:
daniel oeh 2012-12-30 21:27:25 +01:00
parent c342383ede
commit 6163ccbedb
1 changed files with 16 additions and 0 deletions

View File

@ -195,6 +195,17 @@ public class DirectoryChooserActivity extends SherlockActivity {
Log.d(TAG, "Could not change folder: dir is no directory");
}
}
refreshButtonState();
}
/**
* Changes the state of the buttons depending on the currently selected file
* or folder.
*/
private void refreshButtonState() {
if (selectedDir != null) {
butConfirm.setEnabled(isValidFile(selectedDir));
}
}
/** Refresh the contents of the directory that is currently shown. */
@ -301,4 +312,9 @@ public class DirectoryChooserActivity extends SherlockActivity {
}
}
/** Returns true if the selected file or directory would be valid selection. */
private boolean isValidFile(File file) {
return (file != null && file.isDirectory() && file.canRead() && file
.canWrite());
}
}