diff options
| author | rsudev <rasch@munin-soft.de> | 2013-10-18 12:13:35 +0200 |
|---|---|---|
| committer | rsudev <rasch@munin-soft.de> | 2013-10-18 14:07:16 +0200 |
| commit | e6606ad7690c84c9ee03c9195859382e9ae1de6b (patch) | |
| tree | 1c0f361e96954df04df6994065ee9c991856ebc1 /main/src/cgeo/geocaching/SelectMapfileActivity.java | |
| parent | 3e80f82fec4d8148562ae125f1c1ec14f65783f0 (diff) | |
| download | cgeo-e6606ad7690c84c9ee03c9195859382e9ae1de6b.zip cgeo-e6606ad7690c84c9ee03c9195859382e9ae1de6b.tar.gz cgeo-e6606ad7690c84c9ee03c9195859382e9ae1de6b.tar.bz2 | |
Fixes part of #2976, allow to manually select map directory
Add a directory selection button to map selection.
Fix issues with updating map sources preference after selecting a map file.
Fix issues with listing map source if only a directory was defined.
Diffstat (limited to 'main/src/cgeo/geocaching/SelectMapfileActivity.java')
| -rw-r--r-- | main/src/cgeo/geocaching/SelectMapfileActivity.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/SelectMapfileActivity.java b/main/src/cgeo/geocaching/SelectMapfileActivity.java index 8b50c1f..9d86fa5 100644 --- a/main/src/cgeo/geocaching/SelectMapfileActivity.java +++ b/main/src/cgeo/geocaching/SelectMapfileActivity.java @@ -1,14 +1,23 @@ package cgeo.geocaching; +import butterknife.InjectView; +import butterknife.Views; + import cgeo.geocaching.files.AbstractFileListActivity; import cgeo.geocaching.files.IFileSelectionView; import cgeo.geocaching.files.LocalStorage; +import cgeo.geocaching.files.SimpleDirChooser; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.FileSelectionListAdapter; +import org.openintents.intents.FileManagerIntents; + import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; import java.io.File; import java.util.ArrayList; @@ -20,12 +29,40 @@ public class SelectMapfileActivity extends AbstractFileListActivity<FileSelectio super("map"); } + @InjectView(R.id.select_dir) protected Button selectDirectory; + private String mapFile; + private static int REQUEST_DIRECTORY = 1; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Views.inject(this); + mapFile = Settings.getMapFile(); + + selectDirectory.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + try { + final Intent dirChooser = new Intent(FileManagerIntents.ACTION_PICK_DIRECTORY); + dirChooser.putExtra(FileManagerIntents.EXTRA_TITLE, + getString(R.string.simple_dir_chooser_title)); + dirChooser.putExtra(FileManagerIntents.EXTRA_BUTTON_TEXT, + getString(android.R.string.ok)); + startActivityForResult(dirChooser, REQUEST_DIRECTORY); + } catch (android.content.ActivityNotFoundException ex) { + // OI file manager not available + final Intent dirChooser = new Intent(SelectMapfileActivity.this, SimpleDirChooser.class); + dirChooser.putExtra(Intents.EXTRA_START_DIR, LocalStorage.getStorage().getAbsolutePath()); + startActivityForResult(dirChooser, REQUEST_DIRECTORY); + } + } + }); + selectDirectory.setText(getResources().getString(R.string.simple_dir_chooser_title)); + selectDirectory.setVisibility(View.VISIBLE); } @Override @@ -70,4 +107,22 @@ public class SelectMapfileActivity extends AbstractFileListActivity<FileSelectio return this; } + @Override + protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode != RESULT_OK) { + return; + } + + if (requestCode == REQUEST_DIRECTORY) { + final String directory = new File(data.getData().getPath()).getAbsolutePath(); + mapFile = directory; + close(); + } + } + + @Override + protected boolean requireFiles() { + return false; + } } |
