2

我想显示带有目录/文件的所有文件夹(图像、视频、文件),目前只显示带有文件的图像文件夹,但不显示其他文件夹。我试图找到解决方案但没有找到。这是代码及其屏幕截图(http://postimg.org/image/wm5ypbk9d/)。

文件管理器.java

package com.rim.samples.device.mapactiondemo;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.KeypadListener;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.TreeField;
import net.rim.device.api.ui.component.TreeFieldCallback;
import net.rim.device.api.ui.container.MainScreen;

public class FilesManager extends MainScreen {

FTPMessages _ftp = null;
String[] fileList;

// ..................
private final Bitmap openIcon = Bitmap.getBitmapResource("open.png");
private final Bitmap closedIcon = Bitmap.getBitmapResource("closed.png");
private final Bitmap movieIcon = Bitmap.getBitmapResource("movie.png");
private final Bitmap songIcon = Bitmap.getBitmapResource("song.png");
private final Bitmap playIcon = Bitmap.getBitmapResource("play.png");
private final Bitmap imgIcon = Bitmap.getBitmapResource("images.png");
String nodeTen;
int node10;
TreeField myTree;
String[] nodeData;

// ListField to be displayed - null - no Field displayed
// List of entries to be displayed - null or length = 0 means no entries
// protected so that another Thread can update this list....
protected ListDirectory[] _resultsList = null; // entries available for
// display

private ListDirectory _selectedEntry = null;

public FilesManager(FTPMessages ftp) {
    super();
    _ftp = ftp;
    // Setting starting directory
    try {
        /*
         * fileList = _ftp.list(); for (int i = 0; i < fileList.length; i++)
         * { _ftp.cwd(fileList[i]); }
         */
        _ftp.cwd("images");
        _ftp.cwd("files");
        _ftp.cwd("videos");
    } catch (Exception e) {
    }

    this.setTitle("Server File List");

    TreeCallback myCallback = new TreeCallback();
    myTree = new TreeField(myCallback, Field.FOCUSABLE) {
        protected boolean navigationClick(int status, int time) {
            // We'll only override unvarnished navigation click behavior
            if ((status & KeypadListener.STATUS_ALT) == 0
                    && (status & KeypadListener.STATUS_SHIFT) == 0) {
                final int node = getCurrentNode();
                if (getFirstChild(node) == -1) {
                    // Click is on a leaf node. Do some default action or
                    // else fall through.

                    // Note: this will also detect empty folders, which
                    // might or
                    // might not be something your app has to handle
                    Dialog.alert("clicked " + getCookie(node));
                    // TODO: open player screen, etc.
                    return true;
                }
            }
            return super.navigationClick(status, time);
        }
    };

    myTree.setDefaultExpanded(false);
    myTree.setRowHeight(openIcon.getHeight());

    try {
        node10 = myTree.addChildNode(0, _ftp.pwd());
    } catch (Exception e) {
    }

    this.add(myTree);

    refreshList();
}

private void refreshList() {
    // TODO Auto-generated method stub

    _resultsList = null;
    String[] directory = null;
    try {
        directory = _ftp.list();
    } catch (Exception e) {
    }
    if (directory != null && directory.length > 0) {
        _resultsList = new ListDirectory[directory.length];
        for (int i = 0; i < directory.length; i++) {
            _resultsList[i] = new ListDirectory(directory[i],
                    ListDirectory.UNIX_SERVER);
        }
    }

    if (_resultsList != null && _resultsList.length > 0) {
        // we have some results
        for (int i = 0; i < _resultsList.length; i++) {
            String bb = directory[i];
            String nodeFive = new String(bb);
            this.myTree.addChildNode(node10, nodeFive);
        }

    } else {

    }
}

private class TreeCallback implements TreeFieldCallback {
    public void drawTreeItem(TreeField _tree, Graphics g, int node, int y,
            int width, int indent) {
        final int PAD = 8;
        String text = (String) _tree.getCookie(node);
        Bitmap icon = closedIcon;
        if (text.endsWith(".mp3")) {
            icon = songIcon;
        } else if (text.endsWith(".avi")) {
            icon = movieIcon;
        } else if (text.endsWith(".png") || text.endsWith(".jpg")) {
            icon = imgIcon;
        } else if (_tree.getExpanded(node)) {
            icon = openIcon;
        }
        g.drawBitmap(indent, y, icon.getWidth(), icon.getHeight(), icon, 0,
                0);
        // This assumes filenames all contain '.' character!
        if (text.indexOf(".") > 0) {
            // Leaf node, so this is a playable item (movie or song)
            g.drawBitmap(_tree.getWidth() - playIcon.getWidth() - PAD, y
                    + PAD, playIcon.getWidth(), playIcon.getHeight(),
                    playIcon, 0, 0);
        }
        int fontHeight = getFont().getHeight();
        g.drawText(text, indent + icon.getWidth() + PAD,
                y + (_tree.getRowHeight() - fontHeight) / 2);
    }
}

}

与此代码一起使用的其他类,从该链接下载(完整的项目类) http://remote.offroadstudios.com/files/filemanager.zip

您还可以检查服务器上的文件,ip:64.207.150.31:21,用户名:remote,密码:123456789

4

0 回答 0