コード例 #1
0
        private void onItemClicked(object sender, AdapterView.ItemClickEventArgs e)
        {
            Option o = currAdapter.GetItemAtPosition(e.Position);              //may require casting

            if (string.Compare("Folder", o.getData()) == 0)
            {
                dirStack.Push(currentDir);
                currentDir        = new DirectoryInfo(o.getPath());
                currAdapter       = fill(currentDir);
                aListView.Adapter = currAdapter;                // // //  // Instance of FILEARRAYADAPTER/////////////////////////////////////////////////////////////
                //Console.WriteLine("DIRECTORY");
            }
            else if (string.Compare("Parent Directory", o.getData()) == 0)
            {
                //Console.WriteLine (dirStack.Count);
                if (dirStack.Count > 0)
                {
                    currentDir        = dirStack.Pop();
                    currAdapter       = fill(currentDir);
                    aListView.Adapter = currAdapter;
                }
                else
                {
                    throw new NotImplementedException("Move up from highest directory");
                }
            }
            else
            {
                onFileClick(o);
            }
        }
コード例 #2
0
        private FileArrayAdapter fill(DirectoryInfo dirInfo)
        {
            List <Option> dir = new List <Option> ();
            List <Option> fls = new List <Option> ();

            foreach (DirectoryInfo subDir in dirInfo.GetDirectories())
            {
                dir.Add(new Option(subDir.Name, "Folder", subDir.FullName));
            }
            foreach (FileInfo file in dirInfo.GetFiles())
            {
                fls.Add(new Option(
                            file.Name,
                            "File Size: " + file.Length,
                            file.FullName
                            ));
            }
//			dir.Sort();
//			fls.Sort();
            dir.AddRange(fls);
            if (string.Compare(dirInfo.Name, "sdcard", false) != 0)                //NOT the same
            {
                dir.Insert(
                    0,
                    new Option("..", "Parent Directory", dirInfo.Parent.Name)
                    );
            }
            FileArrayAdapter adapter = new FileArrayAdapter(
                this,
                Resource.Layout.ListItem,
                dir
                );

            return(adapter);            // // //  // Instance of FILEARRAYADAPTER
        }
コード例 #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.OpenFileDialog_l);

            aListView            = FindViewById <ListView> (Resource.Id.list);
            aListView.ItemClick += onItemClicked;

            string state = Android.OS.Environment.ExternalStorageState;

            if (Android.OS.Environment.MediaMountedReadOnly.Equals(state) || Android.OS.Environment.MediaMounted.Equals(state))                //////////////////////////////////http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29
            //currentDir = new DirectoryInfo ("/sdcard/DCIM/Camera/");
            {
                currentDir = new DirectoryInfo(Android.OS.Environment.ExternalStorageDirectory + @"/DCIM/Camera/");
                //SetTitle(//CHAR SEQUENCE!!!!! currentDir.Name)
                dirStack.Push(new DirectoryInfo(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath.ToString()));
                dirStack.Push(currentDir.Parent.Parent);
                dirStack.Push(currentDir.Parent);
                try {
                    currAdapter = fill(currentDir);
                } catch (UnauthorizedAccessException ex) {
                    Console.WriteLine("ex " + ex.Message);
                    Console.WriteLine("Try turning on USB Mass Storage only, disconnecting and reconnecting usb, and then turning on USB Debugging mode.");
                }
            }
            else
            {
                Console.WriteLine("Media is not mounted.");
            }
            aListView.Adapter = currAdapter;
        }