Permalink
Browse files

Add workings for proper navigation

  • Loading branch information...
1 parent 1bbdf9e commit 1a7a2ee87b93a269535e903c83c2ca35f1eb0e7f @exallium committed May 13, 2012
View
@@ -1,15 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/list_switch"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
-
+ android:layout_height="fill_parent">
<ListView
android:id="@+id/list_results"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
-
-</LinearLayout>
+ <TextView
+ android:layout_height="fill_parent"
+ android:layout_width="fill_parent"
+ android:textAppearance="@android:style/TextAppearance.Medium"
+ android:paddingTop="8dip"
+ android:gravity="center_horizontal"
+ android:text="@string/list_noitems"
+ />
+</ViewSwitcher>
@@ -3,5 +3,6 @@
<string name="hello">Hello World, ExpressFilesActivity!</string>
<string name="app_name">ExpressFiles</string>
+ <string name="list_noitems">No files to display.</string>
</resources>
@@ -14,6 +14,9 @@
mimemap.put("gif", "image/*");
// Video
+
// Music
+ mimemap.put("mp3", "audio/*");
+ mimemap.put("m4a", "audio/*");
}
}
@@ -16,16 +16,22 @@
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
+import android.widget.Toast;
+import android.widget.ViewSwitcher;
public class ExpressFilesActivity extends Activity {
private static String TAG = "ExpressFilesActivity";
+ private static int CHILD_LIST = 0;
+ private static int CHILD_TEXT = 1;
private ListView listResults;
+ private ViewSwitcher viewSwitcher;
private FileAdapter fileAdapter;
private String workingPath;
private File workingDirectory;
@@ -38,6 +44,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
listResults = (ListView) findViewById(R.id.list_results);
+ viewSwitcher = (ViewSwitcher) findViewById(R.id.list_switch);
// Get the default path we want, and open it.
SharedPreferences prefs = getSharedPreferences("expressfile", Context.MODE_PRIVATE);
@@ -68,21 +75,56 @@ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
Log.d(TAG, item.getName());
- String [] item_split = item.getName().split("[.]");
- String type = item_split[item_split.length - 1];
+ String type = getFileType(item);
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_VIEW);
- intent.setDataAndType(uri, Constants.mimemap.get(type));
- startActivity(intent);
+ try {
+ Intent intent = new Intent();
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.setDataAndType(uri, Constants.mimemap.get(type));
+ startActivity(intent);
+ } catch (Exception e) {
+ Toast.makeText(
+ getApplicationContext(), "Could not open " + item.getName(),
+ Toast.LENGTH_SHORT).show();
+ }
}
}
});
}
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+
+ switch (item.getItemId()) {
+ case android.R.id.home:
+
+ if (workingDirectory.getParentFile() != null) {
+ workingDirectory = workingDirectory.getParentFile();
+ workingPath = workingDirectory.getAbsolutePath();
+ displayList();
+ }
+
+ return true;
+ default:
+ return false;
+ }
+
+ }
+
+ private String getFileType(File item) {
+ String [] item_split = item.getName().split("[.]");
+ return item_split[item_split.length - 1];
+ }
+
private void displayList() {
// XXX: We are assuming the workingPath file exists. This could lead to crashing.
- genWorkingListing();
+ boolean filesExist = genWorkingListing();
+
+ if (!filesExist) {
+ viewSwitcher.setDisplayedChild(1);
+ } else {
+ viewSwitcher.setDisplayedChild(0);
+ }
// We try to sort the list
// XXX: We need to gracefully handle the error
@@ -98,6 +140,12 @@ private void displayList() {
listResults.setAdapter(fileAdapter);
this.getActionBar().setTitle(workingPath);
+
+ if (workingDirectory.getParentFile() != null) {
+ this.getActionBar().setDisplayHomeAsUpEnabled(true);
+ } else {
+ this.getActionBar().setDisplayHomeAsUpEnabled(false);
+ }
}
/**
@@ -110,7 +158,13 @@ private boolean genWorkingListing() {
if (!workingDirectory.isDirectory()) { return false; }
workingListing = new ArrayList<File>();
- for (File f : workingDirectory.listFiles()) {
+
+ File [] fileList = workingDirectory.listFiles();
+ if (fileList == null) {
+ return false;
+ }
+
+ for (File f : fileList) {
// XXX: this is where our regex filter should be placed.
workingListing.add(f);
}

0 comments on commit 1a7a2ee

Please sign in to comment.