diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | main/res/layout/gpx_export_dialog.xml | 1 | ||||
-rw-r--r-- | main/res/layout/init.xml | 36 | ||||
-rw-r--r-- | main/res/layout/simple_dir_chooser.xml | 49 | ||||
-rw-r--r-- | main/res/layout/simple_dir_item.xml | 21 | ||||
-rw-r--r-- | main/res/values-de/strings.xml | 10 | ||||
-rw-r--r-- | main/res/values-it/strings.xml | 2 | ||||
-rw-r--r-- | main/res/values-ja/strings.xml | 2 | ||||
-rw-r--r-- | main/res/values-sv/strings.xml | 2 | ||||
-rw-r--r-- | main/res/values/strings.xml | 10 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 22 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/SettingsActivity.java | 28 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/export/AbstractExport.java | 13 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/export/GpxExport.java | 8 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/files/SimpleDirChooser.java | 238 |
15 files changed, 434 insertions, 11 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml index a2f0597..e866138 100644 --- a/main/AndroidManifest.xml +++ b/main/AndroidManifest.xml @@ -237,5 +237,8 @@ android:windowSoftInputMode="stateHidden" android:configChanges="keyboardHidden|orientation" > </activity> + <activity android:name=".files.SimpleDirChooser" + android:label="@string/app_name"> + </activity> </application> </manifest> diff --git a/main/res/layout/gpx_export_dialog.xml b/main/res/layout/gpx_export_dialog.xml index 86c0862..7c9345f 100644 --- a/main/res/layout/gpx_export_dialog.xml +++ b/main/res/layout/gpx_export_dialog.xml @@ -6,6 +6,7 @@ android:padding="3dip" >
<TextView
+ android:id="@id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/export_gpx_info" />
diff --git a/main/res/layout/init.xml b/main/res/layout/init.xml index 80a12ca..e660b27 100644 --- a/main/res/layout/init.xml +++ b/main/res/layout/init.xml @@ -714,6 +714,42 @@ <RelativeLayout style="@style/separator_horizontal_layout" > <View style="@style/separator_horizontal" /> <TextView style="@style/separator_horizontal_headline" + android:text="@string/init_gpx_exportdir" /> + </RelativeLayout> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="10dip" + android:layout_marginRight="10dip" + android:layout_marginBottom="5dip" + android:layout_gravity="left" + android:padding="3dip" + android:textSize="14dip" + android:textColor="?text_color" + android:textColorLink="?text_color_link" + android:linksClickable="true" + android:autoLink="web" + android:text="@string/init_gpx_exportdir_description" /> + <LinearLayout + android:id="@+id/init_gpx_export_group" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" > + <Button style="@style/button_full" + android:id="@+id/select_gpx_exportdir" + android:text="@string/init_select_gpx_exportdir" + android:layout_width="wrap_content" /> + <EditText style="@style/edittext_full" + android:id="@+id/gpx_exportdir" + android:singleLine="true" + android:lines="1" + android:scrollHorizontally="true" + android:inputType="textNoSuggestions" /> + </LinearLayout> +<!-- ** --> + <RelativeLayout style="@style/separator_horizontal_layout" > + <View style="@style/separator_horizontal" /> + <TextView style="@style/separator_horizontal_headline" android:text="@string/init_altitude" /> </RelativeLayout> <EditText style="@style/edittext_full" diff --git a/main/res/layout/simple_dir_chooser.xml b/main/res/layout/simple_dir_chooser.xml new file mode 100644 index 0000000..491e0a2 --- /dev/null +++ b/main/res/layout/simple_dir_chooser.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical" + android:background="?background_color"> + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:layout_weight="2"> + <RelativeLayout style="@style/separator_horizontal_layout" > + <View style="@style/separator_horizontal" /> + <TextView style="@style/separator_horizontal_headline" + android:text="@string/simple_dir_chooser_title" /> + </RelativeLayout> + <EditText + style="@style/edittext_full" + android:id="@+id/simple_dir_chooser_path" + android:singleLine="true" + android:lines="0" + android:editable="false" + android:scrollHorizontally="true" + android:inputType="textNoSuggestions" /> + </LinearLayout> + <ListView + android:layout_height="fill_parent" + android:layout_width="wrap_content" + android:layout_weight="100" + android:id="@+id/android:list" /> + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:paddingTop="10dip" + android:layout_weight="1"> + <Button style="@style/button_full" + android:id="@+id/simple_dir_chooser_ok" + android:text="@android:string/ok" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + <Button style="@style/button_full" + android:id="@+id/simple_dir_chooser_cancel" + android:text="@android:string/cancel" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + </LinearLayout> +</LinearLayout> diff --git a/main/res/layout/simple_dir_item.xml b/main/res/layout/simple_dir_item.xml new file mode 100644 index 0000000..ec4cd28 --- /dev/null +++ b/main/res/layout/simple_dir_item.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="horizontal" + android:background="?background_color" > + <CheckBox android:text="" + android:id="@+id/CheckBox" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:checked="false" /> + <TextView + android:text="@+id/TextView01" + android:id="@+id/TextView01" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:textStyle="bold" + android:layout_marginTop="5dip" + android:layout_marginLeft="5dip" /> +</LinearLayout> diff --git a/main/res/values-de/strings.xml b/main/res/values-de/strings.xml index f811f44..05cc5a1 100644 --- a/main/res/values-de/strings.xml +++ b/main/res/values-de/strings.xml @@ -425,6 +425,10 @@ <string name="init_mapsources_description">Hier kann die Quelle der benutzen Karte gewählt werden. Alternativ zu Google Maps stehen verschiedene OpenStreetMap-Stile zur Verfügung und daneben auch Karten-Dateien für die Offline-Nutzung (siehe http://code.google.com/p/mapsforge/ für die Details).</string> <string name="init_mapsource_select">Kartenquelle wählen</string> <string name="init_select_mapfile">…</string> + <string name="init_select_gpx_exportdir">…</string> + <string name="init_gpx_exportdir">Verzeichnis für GPX Exporte</string> + <string name="init_gpx_exportdir_description">Hier kann das Verzeichnis für GPX-Exporte gewählt werden.</string> + <string name="init_gpx_exportdir_select">Wähle Verzeichnis für GPX Exporte</string> <string name="init_maptrail">Zeige Spur auf Karte</string> <string name="init_share_after_export">Weiterleiten nach dem Export</string> <string name="init_trackautovisit">Trackables automatisch auf \"besuchen\" setzen</string> @@ -607,6 +611,10 @@ <string name="file_searching">Suche nach passenden Dateien</string> <string name="file_title_searching">Suche</string> + <!-- simple_dir_chooser --> + <string name="simple_dir_chooser_title">Verzeichnis wählen</string> + <string name="simple_dir_chooser_current_path">Pfad:</string> + <!-- gpx --> <string name="gpx_import_loading_caches">Lade Caches aus GPX-Datei</string> <string name="gpx_import_loading_waypoints">Lade Wegpunkte aus GPX-Datei</string> @@ -804,7 +812,7 @@ <string name="export_fieldnotes_onlynew">Nur seit letztem Export</string> <string name="export_fieldnotes_creating">Erstelle Field Notes…</string> <string name="export_gpx">GPX</string> - <string name="export_gpx_info">GPX-Datei wird nach /sdcard/gpx mit dem aktuellen Datum und Zeit als Dateiname exportiert.</string> + <string name="export_gpx_info">GPX-Datei wird nach %1$s mit dem aktuellen Datum und Zeit als Dateiname exportiert.</string> <string name="export_gpx_to">Exportierte GPX-Datei senden an</string> <!-- attribute unknown --> diff --git a/main/res/values-it/strings.xml b/main/res/values-it/strings.xml index 7516a47..a9af5b5 100644 --- a/main/res/values-it/strings.xml +++ b/main/res/values-it/strings.xml @@ -796,7 +796,7 @@ <string name="export_fieldnotes_onlynew">Solo quelli nuovi rispetto all\'ultima esportazione</string> <string name="export_fieldnotes_creating">Creazione Field Notes…</string> <string name="export_gpx">GPX</string> - <string name="export_gpx_info">Il file GPX sarà esportato in /sdcard/gpx con data ed ora correnti come nome file.</string> + <string name="export_gpx_info">Il file GPX sarà esportato in %1$s con data ed ora correnti come nome file.</string> <string name="export_gpx_to">Invia il GPX esportato a</string> <!-- attribute unknown --> diff --git a/main/res/values-ja/strings.xml b/main/res/values-ja/strings.xml index 2aa0291..acfbe4c 100644 --- a/main/res/values-ja/strings.xml +++ b/main/res/values-ja/strings.xml @@ -828,7 +828,7 @@ <string name="export_fieldnotes_onlynew">最後にエクスポートした時から更新がある場合のみ</string> <!-- only new logs since last export/upload line53:FieldnoteExport.java --> <string name="export_fieldnotes_creating">フィールドノートを作成中…</string> <string name="export_gpx">GPX</string> - <string name="export_gpx_info">GPXファイルは/sdcard/gpxフォルダに保存され、ファイル名は現在の日時になります。</string> + <string name="export_gpx_info">GPXファイルは%1$sフォルダに保存され、ファイル名は現在の日時になります。</string> <string name="export_gpx_to">エクスポートしたGPXファイルを送る:</string> <!-- attribute unknown --> diff --git a/main/res/values-sv/strings.xml b/main/res/values-sv/strings.xml index 37fe1c7..21f72a6 100644 --- a/main/res/values-sv/strings.xml +++ b/main/res/values-sv/strings.xml @@ -798,7 +798,7 @@ <string name="export_fieldnotes_onlynew">Bara sedan senaste exporteringen</string> <string name="export_fieldnotes_creating">Skapar Field Notes…</string> <string name="export_gpx">GPX</string> - <string name="export_gpx_info">GPX filen kommer att exporteras till /sdcard/gpx med datum och tid i filnamnet.</string> + <string name="export_gpx_info">GPX filen kommer att exporteras till %1$s med datum och tid i filnamnet.</string> <string name="export_gpx_to">Skicka exporterad GPX till</string> <!-- next things --> diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml index edc81ed..d0b65d3 100644 --- a/main/res/values/strings.xml +++ b/main/res/values/strings.xml @@ -426,6 +426,10 @@ <string name="init_mapsources_description">Here you can select the source for your maps. As an alternative to Google maps various OpenStreetMap styles are available and even offline map files (See <a href="http://code.google.com/p/mapsforge/">http://code.google.com/p/mapsforge/</a> for details).</string> <string name="init_mapsource_select">Select Map Source</string> <string name="init_select_mapfile">…</string> + <string name="init_select_gpx_exportdir">…</string> + <string name="init_gpx_exportdir">GPX Export Directory</string> + <string name="init_gpx_exportdir_description">Here you can select the directory for GPX exports.</string> + <string name="init_gpx_exportdir_select">Select GPX Export Directory</string> <string name="init_maptrail">Show trail on Map</string> <string name="init_share_after_export">Open share menu after GPX export</string> <string name="init_trackautovisit">Set trackables to \"Visited\" as a default</string> @@ -617,6 +621,10 @@ <string name="file_searching">Searching for matching files</string> <string name="file_title_searching">Searching</string> + <!-- simple_dir_chooser --> + <string name="simple_dir_chooser_title">Choose directory</string> + <string name="simple_dir_chooser_current_path">Path:</string> + <!-- gpx --> <string name="gpx_import_loading_caches">Loading caches from .gpx file</string> <string name="gpx_import_loading_waypoints">Loading waypoints file</string> @@ -828,7 +836,7 @@ <string name="export_fieldnotes_onlynew">Only since last export</string> <string name="export_fieldnotes_creating">Creating Field Notes…</string> <string name="export_gpx">GPX</string> - <string name="export_gpx_info">The GPX file will be exported to /sdcard/gpx with current date and time as file name.</string> + <string name="export_gpx_info">The GPX file will be exported to %1$s with current date and time as file name.</string> <string name="export_gpx_to">Send exported GPX to</string> <!-- attribute unknown --> diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index bbcb80b..ee201e2 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -95,6 +95,7 @@ public final class Settings { private static final String KEY_DB_ON_SDCARD = "dbonsdcard"; private static final String KEY_LAST_TRACKABLE_ACTION = "trackableaction"; private static final String KEY_SHARE_AFTER_EXPORT = "shareafterexport"; + private static final String KEY_GPX_EXPORT_DIR = "gpxExportDir"; private final static int unitsMetric = 1; @@ -1166,6 +1167,23 @@ public final class Settings { }); } + public static String getGpxExportDir() { + return sharedPrefs.getString(KEY_GPX_EXPORT_DIR, "/sdcard/gpx"); + } + + public static void setGpxExportDir(final String gpxExportDir) { + editSharedSettings(new PrefRunnable() { + @Override + public void edit(Editor edit) { + edit.putString(KEY_GPX_EXPORT_DIR, gpxExportDir); + } + }); + } + + public static boolean getShareAfterExport() { + return sharedPrefs.getBoolean(KEY_SHARE_AFTER_EXPORT, true); + } + public static void setShareAfterExport(final boolean shareAfterExport) { editSharedSettings(new PrefRunnable() { @Override @@ -1189,10 +1207,6 @@ public final class Settings { }); } - public static boolean getShareAfterExport() { - return sharedPrefs.getBoolean(KEY_SHARE_AFTER_EXPORT, true); - } - public static String getPreferencesName() { // there is currently no Android API to get the file name of the shared preferences return cgeoapplication.getInstance().getPackageName() + "_preferences"; diff --git a/main/src/cgeo/geocaching/SettingsActivity.java b/main/src/cgeo/geocaching/SettingsActivity.java index d70b300..8d802bf 100644 --- a/main/src/cgeo/geocaching/SettingsActivity.java +++ b/main/src/cgeo/geocaching/SettingsActivity.java @@ -7,6 +7,7 @@ import cgeo.geocaching.compatibility.Compatibility; import cgeo.geocaching.connector.gc.Login; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.StatusCode; +import cgeo.geocaching.files.SimpleDirChooser; import cgeo.geocaching.maps.MapProviderFactory; import cgeo.geocaching.maps.interfaces.MapSource; import cgeo.geocaching.network.Cookies; @@ -55,6 +56,8 @@ import java.util.List; public class SettingsActivity extends AbstractActivity { private final static int SELECT_MAPFILE_REQUEST = 1; + private final static int SELECT_GPXDIR_REQUEST = 2; + private ProgressDialog loginDialog = null; private ProgressDialog webDialog = null; @@ -577,6 +580,21 @@ public class SettingsActivity extends AbstractActivity { } }); + // GPX Export directory + final EditText gpxExportDir = (EditText) findViewById(R.id.gpx_exportdir); + gpxExportDir.setText(Settings.getGpxExportDir()); + Button selectGpxExportDir = (Button) findViewById(R.id.select_gpx_exportdir); + selectGpxExportDir.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + Intent dirChooser = new Intent(SettingsActivity.this, SimpleDirChooser.class); + dirChooser.putExtra(SimpleDirChooser.START_DIR, Settings.getGpxExportDir()); + startActivityForResult(dirChooser, SELECT_GPXDIR_REQUEST); + } + }); + + // Display trail on map final CheckBox trailButton = (CheckBox) findViewById(R.id.trail); trailButton.setChecked(Settings.isMapTrail()); trailButton.setOnClickListener(new View.OnClickListener() { @@ -918,6 +936,16 @@ public class SettingsActivity extends AbstractActivity { } initMapfileEdittext(true); } + if (requestCode == SELECT_GPXDIR_REQUEST) { + if (resultCode == RESULT_OK) { + if (data.hasExtra("chosenDir")) { + Settings.setGpxExportDir(data.getStringExtra("chosenDir")); + } + } + EditText gpxExportDir = (EditText) findViewById(R.id.gpx_exportdir); + gpxExportDir.setText(Settings.getGpxExportDir()); + gpxExportDir.requestFocus(); + } } public static void startActivity(Context fromActivity) { diff --git a/main/src/cgeo/geocaching/export/AbstractExport.java b/main/src/cgeo/geocaching/export/AbstractExport.java index 0923cef..72ea544 100644 --- a/main/src/cgeo/geocaching/export/AbstractExport.java +++ b/main/src/cgeo/geocaching/export/AbstractExport.java @@ -25,6 +25,19 @@ abstract class AbstractExport implements Export { return cgeoapplication.getInstance().getString(resourceId); } + /** + * Generates a localized string from a resource id. + * + * @param resourceId + * the resource id of the string + * @param params + * The parameter + * @return localized string + */ + protected static String getString(int resourceId, Object... params) { + return cgeoapplication.getInstance().getString(resourceId, params); + } + @Override public String toString() { // used in the array adapter of the dialog showing the exports diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java index 9bc3963..8af85a8 100644 --- a/main/src/cgeo/geocaching/export/GpxExport.java +++ b/main/src/cgeo/geocaching/export/GpxExport.java @@ -26,6 +26,7 @@ import android.os.Environment; import android.view.View; import android.widget.Button; import android.widget.CheckBox; +import android.widget.TextView; import java.io.BufferedWriter; import java.io.File; @@ -38,7 +39,6 @@ import java.util.Date; import java.util.List; class GpxExport extends AbstractExport { - private static final File exportLocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/gpx"); private static final SimpleDateFormat dateFormatZ = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); protected GpxExport() { @@ -70,6 +70,9 @@ class GpxExport extends AbstractExport { View layout = activity.getLayoutInflater().inflate(R.layout.gpx_export_dialog, null); setView(layout); + final TextView text = (TextView) layout.findViewById(R.id.info); + text.setText(getString(R.string.export_gpx_info, Settings.getGpxExportDir())); + final CheckBox shareOption = (CheckBox) layout.findViewById(R.id.share); shareOption.setChecked(Settings.getShareAfterExport()); @@ -127,10 +130,11 @@ class GpxExport extends AbstractExport { } try { + final File exportLocation = new File(Settings.getGpxExportDir()); exportLocation.mkdirs(); final SimpleDateFormat fileNameDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - exportFile = new File(exportLocation.toString() + File.separatorChar + "export_" + fileNameDateFormat.format(new Date()) + ".gpx"); + exportFile = new File(Settings.getGpxExportDir() + File.separatorChar + "export_" + fileNameDateFormat.format(new Date()) + ".gpx"); gpx = new BufferedWriter(new FileWriter(exportFile)); diff --git a/main/src/cgeo/geocaching/files/SimpleDirChooser.java b/main/src/cgeo/geocaching/files/SimpleDirChooser.java new file mode 100644 index 0000000..57cbc0c --- /dev/null +++ b/main/src/cgeo/geocaching/files/SimpleDirChooser.java @@ -0,0 +1,238 @@ +/** + * + */ +package cgeo.geocaching.files; + +import cgeo.geocaching.R; +import cgeo.geocaching.activity.ActivityMixin; + +import android.app.ListActivity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.TextView; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Dialog for choosing a file or directory. + */ +public class SimpleDirChooser extends ListActivity { + public static final String START_DIR = "start_dir"; + private static final String PARENT_DIR = ".. "; + private File currentDir; + private FileArrayAdapter adapter; + private CheckBox lastBoxChecked = null; + private Button okButton = null; + private String checkedText = null; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final Bundle extras = getIntent().getExtras(); + String startDir = extras.getString(START_DIR); + if (startDir == null) { + startDir = "/sdcard"; + } else { + startDir = startDir.substring(0, startDir.lastIndexOf(File.separatorChar)); + } + currentDir = new File(startDir); + + ActivityMixin.setTheme(this); + setContentView(R.layout.simple_dir_chooser); + setTitle(this.getResources().getString(R.string.simple_dir_chooser_title)); + + fill(currentDir); + + okButton = (Button) findViewById(R.id.simple_dir_chooser_ok); + okButton.setEnabled(false); + okButton.setVisibility(View.INVISIBLE); + okButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + String chosenDirName = File.separator + checkedText; + intent.putExtra("chosenDir", currentDir.getAbsolutePath() + chosenDirName); + setResult(RESULT_OK, intent); + finish(); + } + }); + + Button cancelButton = (Button) findViewById(R.id.simple_dir_chooser_cancel); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + setResult(RESULT_CANCELED, intent); + finish(); + } + }); + } + + private void fill(File dir) { + EditText path = (EditText) findViewById(R.id.simple_dir_chooser_path); + path.setText(this.getResources().getString(R.string.simple_dir_chooser_current_path) + " " + dir.getAbsolutePath()); + final File[] dirs = dir.listFiles(new DirOnlyFilenameFilter()); + List<Option> listDirs = new ArrayList<Option>(); + try { + for (File currentDir : dirs) { + listDirs.add(new Option(currentDir.getName(), currentDir.getAbsolutePath())); + } + } catch (Exception e) { + } + Collections.sort(listDirs); + if (dir.getParent() != null) { + listDirs.add(0, new Option(PARENT_DIR, dir.getParent())); + } + this.adapter = new FileArrayAdapter(SimpleDirChooser.this, R.layout.simple_dir_item, listDirs); + this.setListAdapter(adapter); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + } + + public class FileArrayAdapter extends ArrayAdapter<Option> { + + private Context c; + private int id; + private List<Option> items; + + public FileArrayAdapter(Context context, int simpleDirItemResId, List<Option> objects) { + super(context, simpleDirItemResId, objects); + c = context; + id = simpleDirItemResId; + items = objects; + } + + @Override + public Option getItem(int i) { + return items.get(i); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View v = convertView; + if (v == null) { + LayoutInflater vi = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + v = vi.inflate(id, null); + } + + final Option o = items.get(position); + if (o != null) { + TextView t1 = (TextView) v.findViewById(R.id.TextView01); + if (t1 != null) { + t1.setOnClickListener(new OnTextViewClickListener(position)); + t1.setText(o.getName()); + } + CheckBox check = (CheckBox) v.findViewById(R.id.CheckBox); + if (check != null) { + check.setOnClickListener(new OnCheckBoxClickListener(o.getName())); + } + } + return v; + } + } + + public class OnTextViewClickListener implements OnClickListener { + private int position; + + OnTextViewClickListener(int position) { + this.position = position; + } + + @Override + public void onClick(View arg0) { + Option o = adapter.getItem(position); + if (o.getName().equals(PARENT_DIR)) { + currentDir = new File(o.getPath()); + fill(currentDir); + } else { + File dir = new File(o.getPath()); + if (dir.list(new DirOnlyFilenameFilter()).length > 0) { + currentDir = dir; + fill(currentDir); + } + } + } + } + + public class OnCheckBoxClickListener implements OnClickListener { + private String checkedText; + + OnCheckBoxClickListener(String checkedText) { + this.checkedText = checkedText; + } + + @Override + public void onClick(View arg0) { + CheckBox check = (CheckBox) arg0; + if (lastBoxChecked == check) { + check.setChecked(false); + lastBoxChecked = null; + okButton.setEnabled(false); + okButton.setVisibility(View.INVISIBLE); + SimpleDirChooser.this.checkedText = ""; + } else { + if (lastBoxChecked != null) { + lastBoxChecked.setChecked(false); + } + check.setChecked(true); + lastBoxChecked = check; + okButton.setEnabled(true); + okButton.setVisibility(View.VISIBLE); + SimpleDirChooser.this.checkedText = checkedText; + } + } + } + + public class Option implements Comparable<Option> { + private String name; + private String path; + + public Option(String n, String p) { + name = n; + path = p; + } + + public String getName() { + return name; + } + + public String getPath() { + return path; + } + + @Override + public int compareTo(Option o) { + if (o != null && this.name != null) { + return this.name.toLowerCase().compareTo(o.getName().toLowerCase()); + } + throw new IllegalArgumentException(""); + } + } + + public class DirOnlyFilenameFilter implements FilenameFilter { + + @Override + public boolean accept(File dir, String filename) { + File file = new File(dir, filename); + return file.isDirectory(); + } + + } +} |