aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/SettingsActivity.java116
-rw-r--r--main/src/org/openintents/intents/FileManagerIntents.java127
2 files changed, 198 insertions, 45 deletions
diff --git a/main/src/cgeo/geocaching/SettingsActivity.java b/main/src/cgeo/geocaching/SettingsActivity.java
index 0eaaa39..46cf5ed 100644
--- a/main/src/cgeo/geocaching/SettingsActivity.java
+++ b/main/src/cgeo/geocaching/SettingsActivity.java
@@ -23,6 +23,7 @@ import ch.boye.httpclientandroidlib.HttpResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openintents.intents.FileManagerIntents;
import android.app.ProgressDialog;
import android.content.Context;
@@ -566,9 +567,7 @@ public class SettingsActivity extends AbstractActivity {
@Override
public void onClick(View v) {
- Intent dirChooser = new Intent(SettingsActivity.this, SimpleDirChooser.class);
- dirChooser.putExtra(SimpleDirChooser.START_DIR, Settings.getCustomRenderThemeBaseFolder());
- startActivityForResult(dirChooser, SELECT_THEMEFOLDER_REQUEST);
+ selectDirectory(Settings.getCustomRenderThemeBaseFolder(), SELECT_THEMEFOLDER_REQUEST);
}
});
@@ -580,9 +579,7 @@ public class SettingsActivity extends AbstractActivity {
@Override
public void onClick(View v) {
- Intent dirChooser = new Intent(SettingsActivity.this, SimpleDirChooser.class);
- dirChooser.putExtra(SimpleDirChooser.START_DIR, Settings.getGpxExportDir());
- startActivityForResult(dirChooser, SELECT_GPX_EXPORT_REQUEST);
+ selectDirectory(Settings.getGpxExportDir(), SELECT_GPX_EXPORT_REQUEST);
}
});
@@ -594,9 +591,7 @@ public class SettingsActivity extends AbstractActivity {
@Override
public void onClick(View v) {
- Intent dirChooser = new Intent(SettingsActivity.this, SimpleDirChooser.class);
- dirChooser.putExtra(SimpleDirChooser.START_DIR, Settings.getGpxImportDir());
- startActivityForResult(dirChooser, SELECT_GPX_IMPORT_REQUEST);
+ selectDirectory(Settings.getGpxImportDir(), SELECT_GPX_IMPORT_REQUEST);
}
});
@@ -955,9 +950,12 @@ public class SettingsActivity extends AbstractActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
+ if (resultCode != RESULT_OK) {
+ return;
+ }
- if (requestCode == SELECT_MAPFILE_REQUEST) {
- if (resultCode == RESULT_OK) {
+ switch (requestCode) {
+ case SELECT_MAPFILE_REQUEST:
if (data.hasExtra("mapfile")) {
final String mapFile = data.getStringExtra("mapfile");
Settings.setMapFile(mapFile);
@@ -965,48 +963,76 @@ public class SettingsActivity extends AbstractActivity {
showToast(res.getString(R.string.warn_invalid_mapfile));
}
}
- }
- updateMapSourceMenu();
- initMapDirectoryEdittext(true);
- }
- if (requestCode == SELECT_GPX_EXPORT_REQUEST) {
- checkDirectory(resultCode, data, R.id.gpx_exportdir, new RunnableWithArgument<String>() {
+ updateMapSourceMenu();
+ initMapDirectoryEdittext(true);
+ break;
+ case SELECT_GPX_EXPORT_REQUEST:
+ checkDirectory(resultCode, data, R.id.gpx_exportdir, new RunnableWithArgument<String>() {
- @Override
- public void run(String directory) {
- Settings.setGpxExportDir(directory);
- }
- });
- }
- if (requestCode == SELECT_GPX_IMPORT_REQUEST) {
- checkDirectory(resultCode, data, R.id.gpx_importdir, new RunnableWithArgument<String>() {
+ @Override
+ public void run(String directory) {
+ Settings.setGpxExportDir(directory);
+ }
+ });
+ break;
+ case SELECT_GPX_IMPORT_REQUEST:
+ checkDirectory(resultCode, data, R.id.gpx_importdir, new RunnableWithArgument<String>() {
- @Override
- public void run(String directory) {
- Settings.setGpxImportDir(directory);
- }
- });
- }
- if (requestCode == SELECT_THEMEFOLDER_REQUEST) {
- checkDirectory(resultCode, data, R.id.themefolder, new RunnableWithArgument<String>() {
+ @Override
+ public void run(String directory) {
+ Settings.setGpxImportDir(directory);
+ }
+ });
+ break;
+ case SELECT_THEMEFOLDER_REQUEST:
+ checkDirectory(resultCode, data, R.id.themefolder, new RunnableWithArgument<String>() {
- @Override
- public void run(String directory) {
- Settings.setCustomRenderThemeBaseFolder(directory);
- }
- });
+ @Override
+ public void run(String directory) {
+ Settings.setCustomRenderThemeBaseFolder(directory);
+ }
+ });
+ break;
+ default:
+ throw new IllegalArgumentException();
}
}
private void checkDirectory(int resultCode, Intent data, int textField, RunnableWithArgument<String> runnableSetDir) {
- if (resultCode == RESULT_OK) {
- if (data.hasExtra(SimpleDirChooser.EXTRA_CHOSEN_DIR)) {
- final String directory = data.getStringExtra(SimpleDirChooser.EXTRA_CHOSEN_DIR);
- runnableSetDir.run(directory);
- EditText directoryText = (EditText) findViewById(textField);
- directoryText.setText(directory);
- directoryText.requestFocus();
+ if (resultCode != RESULT_OK) {
+ return;
+ }
+ String directory = null;
+ // we may come back from either our selfmade chooser or from the Open Intent manager
+ if (data.hasExtra(SimpleDirChooser.EXTRA_CHOSEN_DIR)) {
+ directory = data.getStringExtra(SimpleDirChooser.EXTRA_CHOSEN_DIR);
+ }
+ else {
+ directory = new File(data.getData().getPath()).getAbsolutePath();
+ }
+ if (StringUtils.isNotBlank(directory)) {
+ runnableSetDir.run(directory);
+ EditText directoryText = (EditText) findViewById(textField);
+ directoryText.setText(directory);
+ directoryText.requestFocus();
+ }
+ }
+
+ private void selectDirectory(String startDirectory, int directoryKind) {
+ Intent dirChooser;
+ try {
+ dirChooser = new Intent(FileManagerIntents.ACTION_PICK_DIRECTORY);
+ if (StringUtils.isNotBlank(startDirectory)) {
+ dirChooser.setData(Uri.parse("file://" + new File(startDirectory).getAbsolutePath()));
}
+ dirChooser.putExtra(FileManagerIntents.EXTRA_TITLE, res.getString(R.string.simple_dir_chooser_title));
+ dirChooser.putExtra(FileManagerIntents.EXTRA_BUTTON_TEXT, res.getString(android.R.string.ok));
+ startActivityForResult(dirChooser, directoryKind);
+ } catch (android.content.ActivityNotFoundException ex) {
+ // OI file manager not available
+ dirChooser = new Intent(SettingsActivity.this, SimpleDirChooser.class);
+ dirChooser.putExtra(SimpleDirChooser.START_DIR, startDirectory);
+ startActivityForResult(dirChooser, directoryKind);
}
}
diff --git a/main/src/org/openintents/intents/FileManagerIntents.java b/main/src/org/openintents/intents/FileManagerIntents.java
new file mode 100644
index 0000000..8ff10c8
--- /dev/null
+++ b/main/src/org/openintents/intents/FileManagerIntents.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2008 OpenIntents.org
+ *
+ * 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.
+ */
+
+package org.openintents.intents;
+
+/**
+ * Provides OpenIntents actions, extras, and categories used by providers.
+ * <p>These specifiers extend the standard Android specifiers.</p>
+ */
+public final class FileManagerIntents {
+
+ /**
+ * Activity Action: Pick a file through the file manager, or let user
+ * specify a custom file name.
+ * Data is the current file name or file name suggestion.
+ * Returns a new file name as file URI in data.
+ *
+ * <p>Constant Value: "org.openintents.action.PICK_FILE"</p>
+ */
+ public static final String ACTION_PICK_FILE = "org.openintents.action.PICK_FILE";
+
+ /**
+ * Activity Action: Pick a directory through the file manager, or let user
+ * specify a custom file name.
+ * Data is the current directory name or directory name suggestion.
+ * Returns a new directory name as file URI in data.
+ *
+ * <p>Constant Value: "org.openintents.action.PICK_DIRECTORY"</p>
+ */
+ public static final String ACTION_PICK_DIRECTORY = "org.openintents.action.PICK_DIRECTORY";
+
+ /**
+ * Activity Action: Move, copy or delete after select entries.
+ * Data is the current directory name or directory name suggestion.
+ *
+ * <p>Constant Value: "org.openintents.action.MULTI_SELECT"</p>
+ */
+ public static final String ACTION_MULTI_SELECT = "org.openintents.action.MULTI_SELECT";
+
+ public static final String ACTION_SEARCH_STARTED = "org.openintents.action.SEARCH_STARTED";
+
+ public static final String ACTION_SEARCH_FINISHED = "org.openintens.action.SEARCH_FINISHED";
+
+ /**
+ * The title to display.
+ *
+ * <p>This is shown in the title bar of the file manager.</p>
+ *
+ * <p>Constant Value: "org.openintents.extra.TITLE"</p>
+ */
+ public static final String EXTRA_TITLE = "org.openintents.extra.TITLE";
+
+ /**
+ * The text on the button to display.
+ *
+ * <p>Depending on the use, it makes sense to set this to "Open" or "Save".</p>
+ *
+ * <p>Constant Value: "org.openintents.extra.BUTTON_TEXT"</p>
+ */
+ public static final String EXTRA_BUTTON_TEXT = "org.openintents.extra.BUTTON_TEXT";
+
+ /**
+ * Flag indicating to show only writeable files and folders.
+ *
+ * <p>Constant Value: "org.openintents.extra.WRITEABLE_ONLY"</p>
+ */
+ public static final String EXTRA_WRITEABLE_ONLY = "org.openintents.extra.WRITEABLE_ONLY";
+
+ /**
+ * The path to prioritize in search. Usually denotes the path the user was on when the search was initiated.
+ *
+ * <p>Constant Value: "org.openintents.extra.SEARCH_INIT_PATH"</p>
+ */
+ public static final String EXTRA_SEARCH_INIT_PATH = "org.openintents.extra.SEARCH_INIT_PATH";
+
+ /**
+ * The search query as sent to SearchService.
+ *
+ * <p>Constant Value: "org.openintents.extra.SEARCH_QUERY"</p>
+ */
+ public static final String EXTRA_SEARCH_QUERY = "org.openintents.extra.SEARCH_QUERY";
+
+ /**
+ * <p>Constant Value: "org.openintents.extra.DIR_PATH"</p>
+ */
+ public static final String EXTRA_DIR_PATH = "org.openintents.extra.DIR_PATH";
+
+ /**
+ * Extension by which to filter.
+ *
+ * <p>Constant Value: "org.openintents.extra.FILTER_FILETYPE"</p>
+ */
+ public static final String EXTRA_FILTER_FILETYPE = "org.openintents.extra.FILTER_FILETYPE";
+
+ /**
+ * Mimetype by which to filter.
+ *
+ * <p>Constant Value: "org.openintents.extra.FILTER_MIMETYPE"</p>
+ */
+ public static final String EXTRA_FILTER_MIMETYPE = "org.openintents.extra.FILTER_MIMETYPE";
+
+ /**
+ * Only show directories.
+ *
+ * <p>Constant Value: "org.openintents.extra.DIRECTORIES_ONLY"</p>
+ */
+ public static final String EXTRA_DIRECTORIES_ONLY = "org.openintents.extra.DIRECTORIES_ONLY";
+
+ public static final String EXTRA_DIALOG_FILE_HOLDER = "org.openintents.extra.DIALOG_FILE";
+
+ public static final String EXTRA_IS_GET_CONTENT_INITIATED = "org.openintents.extra.ENABLE_ACTIONS";
+
+ public static final String EXTRA_FILENAME = "org.openintents.extra.FILENAME";
+}