Implemented directory navigation
This commit is contained in:
parent
8726ea18c0
commit
2f86f4f4ae
@ -38,8 +38,8 @@
|
||||
android:layout_height="60dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="@drawable/borderless_button"
|
||||
android:src="@attr/navigation_up" />
|
||||
android:background="?attr/borderless_button"
|
||||
android:src="?attr/navigation_up" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvSelectedFolderLabel"
|
||||
@ -56,10 +56,15 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvSelectedFolder"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@id/txtvSelectedFolderLabel"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_toRightOf="@id/butNavUp"
|
||||
android:ellipsize="middle" />
|
||||
android:ellipsize="start"
|
||||
android:scrollHorizontally="true"
|
||||
android:singleLine="true" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
|
@ -51,7 +51,7 @@
|
||||
android:title="@string/pref_revokeAccess_title" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/other_pref" >
|
||||
<Preference
|
||||
<Preference android:title="@string/choose_data_directory" android:key="prefChooseDataDir"/><Preference
|
||||
android:key="prefFlattrThisApp"
|
||||
android:summary="@string/pref_flattr_this_app_sum"
|
||||
android:title="@string/pref_flattr_this_app_title" >
|
||||
@ -60,6 +60,7 @@
|
||||
android:key="prefAbout"
|
||||
android:title="@string/about_pref" />
|
||||
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
@ -1,7 +1,20 @@
|
||||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -9,6 +22,7 @@ import com.actionbarsherlock.app.SherlockActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.PodcastApp;
|
||||
import de.danoeh.antennapod.R;
|
||||
|
||||
@ -18,21 +32,114 @@ public class DirectoryChooserActivity extends SherlockActivity {
|
||||
|
||||
private Button butConfirm;
|
||||
private Button butCancel;
|
||||
private Button butNavUp;
|
||||
private ImageButton butNavUp;
|
||||
private TextView txtvSelectedFolder;
|
||||
private ListView listDirectories;
|
||||
|
||||
|
||||
private ArrayAdapter<String> listDirectoriesAdapter;
|
||||
private ArrayList<String> filenames;
|
||||
private File selectedDir;
|
||||
private File[] filesInDir;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(PodcastApp.getThemeResourceId());
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
setContentView(R.layout.directory_chooser);
|
||||
butConfirm = (Button) findViewById(R.id.butConfirm);
|
||||
butCancel = (Button) findViewById(R.id.butCancel);
|
||||
butNavUp = (Button) findViewById(R.id.butNavUp);
|
||||
butNavUp = (ImageButton) findViewById(R.id.butNavUp);
|
||||
txtvSelectedFolder = (TextView) findViewById(R.id.txtvSelectedFolder);
|
||||
listDirectories = (ListView) findViewById(R.id.directory_list);
|
||||
|
||||
butConfirm.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
butCancel.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
listDirectories.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapter, View view,
|
||||
int position, long id) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Selected index: " + position);
|
||||
if (filesInDir != null && position >= 0
|
||||
&& position < filesInDir.length) {
|
||||
changeDirectory(filesInDir[position]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
butNavUp.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
File parent = null;
|
||||
if (selectedDir != null
|
||||
&& (parent = selectedDir.getParentFile()) != null) {
|
||||
changeDirectory(parent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
filenames = new ArrayList<String>();
|
||||
listDirectoriesAdapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_list_item_1, filenames);
|
||||
listDirectories.setAdapter(listDirectoriesAdapter);
|
||||
changeDirectory(Environment.getExternalStorageDirectory());
|
||||
}
|
||||
|
||||
private void changeDirectory(File dir) {
|
||||
if (dir != null && dir.isDirectory()) {
|
||||
File[] contents = dir.listFiles();
|
||||
if (contents != null) {
|
||||
int numDirectories = 0;
|
||||
for (File f : contents) {
|
||||
if (f.isDirectory()) {
|
||||
numDirectories++;
|
||||
}
|
||||
}
|
||||
filesInDir = new File[numDirectories];
|
||||
filenames.clear();
|
||||
for (int i = 0, counter = 0; i < numDirectories; counter++) {
|
||||
if (contents[counter].isDirectory()) {
|
||||
filesInDir[i] = contents[counter];
|
||||
filenames.add(contents[counter].getName());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Arrays.sort(filesInDir);
|
||||
Collections.sort(filenames);
|
||||
selectedDir = dir;
|
||||
txtvSelectedFolder.setText(dir.getAbsolutePath());
|
||||
listDirectoriesAdapter.notifyDataSetChanged();
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Changed directory to " + dir.getAbsolutePath());
|
||||
} else {
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Could not change folder: contents of dir were null");
|
||||
}
|
||||
} else {
|
||||
if (dir == null) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Could not change folder: dir was null");
|
||||
} else {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Could not change folder: dir is no directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,7 +148,4 @@ public class DirectoryChooserActivity extends SherlockActivity {
|
||||
inflater.inflate(R.menu.directory_chooser, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public class PreferenceActivity extends SherlockPreferenceActivity {
|
||||
private static final String PREF_FLATTR_REVOKE = "prefRevokeAccess";
|
||||
private static final String PREF_OPML_EXPORT = "prefOpmlExport";
|
||||
private static final String PREF_ABOUT = "prefAbout";
|
||||
private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@ -84,6 +85,15 @@ public class PreferenceActivity extends SherlockPreferenceActivity {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(PreferenceActivity.this, DirectoryChooserActivity.class));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
findPreference(PodcastApp.PREF_THEME).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user