Added 'set to default folder' menu button

This commit is contained in:
daniel oeh 2012-12-30 21:51:59 +01:00
parent 236e467657
commit 65491d5436
4 changed files with 18 additions and 11 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/new_folder_item" android:title="@string/create_folder_label" android:showAsAction="ifRoom|withText"></item>
<item android:id="@+id/set_to_default_folder_item" android:showAsAction="collapseActionView" android:title="@string/set_to_default_folder"></item>
</menu>

View File

@ -226,5 +226,6 @@
<string name="create_folder_error">Could not create folder</string>
<string name="folder_not_empty_dialog_title">Folder is not empty</string>
<string name="folder_not_empty_dialog_msg">The folder you have selected is not empty. Media downloads and other data will be placed directly in this folder. Continue anyway?</string>
<string name="set_to_default_folder">Set to default folder</string>
</resources>

View File

@ -158,13 +158,19 @@ public class DirectoryChooserActivity extends SherlockActivity {
changeDirectory(Environment.getExternalStorageDirectory());
}
/** Finishes the activity and returns the selected folder as a result. */
/**
* Finishes the activity and returns the selected folder as a result. The
* selected folder can also be null.
*/
private void returnSelectedFolder() {
if (AppConfig.DEBUG)
if (selectedDir != null && AppConfig.DEBUG)
Log.d(TAG, "Returning " + selectedDir.getAbsolutePath()
+ " as result");
Intent resultData = new Intent();
resultData.putExtra(RESULT_SELECTED_DIR, selectedDir.getAbsolutePath());
if (selectedDir != null) {
resultData.putExtra(RESULT_SELECTED_DIR,
selectedDir.getAbsolutePath());
}
setResult(RESULT_CODE_DIR_SELECTED, resultData);
finish();
}
@ -299,6 +305,10 @@ public class DirectoryChooserActivity extends SherlockActivity {
case R.id.new_folder_item:
openNewFolderDialog();
return true;
case R.id.set_to_default_folder_item:
selectedDir = null;
returnSelectedFolder();
return true;
default:
return false;
}

View File

@ -177,14 +177,9 @@ public class PreferenceActivity extends SherlockPreferenceActivity {
if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
String dir = data
.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR);
if (dir != null) {
if (AppConfig.DEBUG)
Log.d(TAG, "Setting data folder");
PodcastApp.getInstance().setDataFolder(dir);
} else {
if (AppConfig.DEBUG)
Log.d(TAG, "Result from DirectoryChooser was null");
}
if (AppConfig.DEBUG)
Log.d(TAG, "Setting data folder");
PodcastApp.getInstance().setDataFolder(dir);
}
}