Code example for File

Methods: getParentFile, isDirectory, toString

0
     * Call this, when the user presses the up button 
     */ 
    public void onNavigateUp() { 
        File parentDir = null;
        if(mDirectory != null) {
            parentDir = mDirectory.getParentFile();  // can be null
        } 
        listDirectory(parentDir);
    } 
 
     
    /** 
     * Use this to query the {@link File} object for the directory 
     * that is currently being displayed by this fragment 
     *  
     * @return File     The currently displayed directory 
     */ 
    public File getCurrentDirectory(){
        return mDirectory;
    } 
     
     
    /** 
     * Calls {@link LocalFileListFragment#listDirectory(File)} with a null parameter 
     * to refresh the current directory. 
     */ 
    public void listDirectory(){ 
        listDirectory(null); 
    } 
     
     
    /** 
     * Lists the given directory on the view. When the input parameter is null, 
     * it will either refresh the last known directory. list the root 
     * if there never was a directory. 
     *  
     * @param directory     Directory to be listed 
     */ 
    public void listDirectory(File directory) {
         
        // Check input parameters for null 
        if(directory == null) {
            if(mDirectory != null){
                directory = mDirectory;
            } else { 
                directory = Environment.getExternalStorageDirectory();  // TODO be careful with the state of the storage; could not be available
                if (directory == null) return; // no files to show
            } 
        } 
         
         
        // if that's not a directory -> List its parent 
        if(!directory.isDirectory()){
            Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString());
            directory = directory.getParentFile();
        } 
 
        mList.clearChoices();   // by now, only files in the same directory will be kept as selected 
        mAdapter.swapDirectory(directory);
        if (mDirectory == null || !mDirectory.equals(directory)) {