FileDocCategorySizeDatePackage
FileList.javaAPI DocAndroid 1.5 API4672Wed May 06 22:42:02 BST 2009com.android.dumprendertree

FileList

public abstract class FileList extends android.app.ListActivity

Fields Summary
protected String
mPath
protected int
mBaseLength
protected String
mFocusFile
protected int
mFocusIndex
Constructors Summary
Methods Summary
protected voidaddItem(java.util.List data, java.lang.String name, java.lang.String path)

        HashMap temp = new HashMap();
        temp.put("title", name);
        temp.put("path", path);
        data.add(temp);
    
abstract booleanfileFilter(java.io.File f)

protected java.util.ListgetData()

        List myData = new ArrayList<HashMap>();
        
        File f = new File(mPath);
        if (!f.exists()) {
        	addItem(myData, "!LayoutTests path missing!", "");
        	return myData;
        }
        String[] files = f.list();
        Arrays.sort(files);

        for (int i = 0; i < files.length; i++) {
        	StringBuilder sb = new StringBuilder(mPath);
        	sb.append(File.separatorChar);
        	sb.append(files[i]);
        	String path = sb.toString();
        	File c = new File(path);
        	if (fileFilter(c)) {
	        	if (c.isDirectory()) {
	        		addItem(myData, "<"+files[i]+">", path);
	        		if (mFocusFile != null && mFocusFile.equals(files[i]))
	        			mFocusIndex = myData.size()-1;
	        	}
	        	else
	        	    addItem(myData, files[i], path);
        	}
        }
        
        return myData;
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        setupPath();
        updateList();
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

		switch (keyCode)
		{
			case KeyEvent.KEYCODE_DPAD_LEFT:
				if (mPath.length() > mBaseLength) {
					File f = new File(mPath);
					mFocusFile = f.getName(); 
					mFocusIndex = 0;
					f = f.getParentFile();
					mPath = f.getPath();
					updateList();
					return true;
				}
				break;
				
			case KeyEvent.KEYCODE_DPAD_RIGHT:
				{
					Map map = (Map) getListView().getItemAtPosition(getListView().getSelectedItemPosition());
					String path = (String)map.get("path");
					if ((new File(path)).isDirectory()) {
						mPath = path;
				        mFocusFile = null;
						updateList();
					} else {
						processFile(path, false);
					}
                    return true;
				}
	
			default:
				break;
		}
		return super.onKeyDown(keyCode, event);
	
protected voidonListItemClick(android.widget.ListView l, android.view.View v, int position, long id)

    	Map map = (Map) l.getItemAtPosition(position);
    	String path = (String)map.get("path");

        if ((new File(path)).isDirectory()) {
            mPath = path;
            mFocusFile = null;
            updateList();
        } else {
            processFile(path, false);
        }
    
abstract voidprocessFile(java.lang.String filename, boolean selection)

protected voidsetupPath()

    	mPath = "/sdcard/android/layout_tests";
    	mBaseLength = mPath.length();
    
protected voidupdateList()

        setListAdapter(new SimpleAdapter(this,
                getData(),
                android.R.layout.simple_list_item_1,
                new String[] {"title"},
                new int[] {android.R.id.text1}));
        String title = mPath; //.substring(mBaseLength-11); // show the word LayoutTests
        setTitle(title);
        getListView().setSelection(mFocusIndex);