Android Open Source - Gui2Go File Helper






From Project

Back to project page Gui2Go.

License

The source code is released under:

MIT License

If you think the Android project Gui2Go listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ami.gui2go.utils;
/*  ww w.ja  va2s .c  om*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;

import com.ami.gui2go.models.ProjectInfo;

import android.content.Context;
import android.os.Environment;

public class FileHelper
{
  public static boolean deleteDir(File path)
  {
    if (path.exists()) {
      File[] files = path.listFiles();
      for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
          deleteDir(files[i]);
        } else {
          files[i].delete();
        }
      }
    }
    return (path.delete());
  }

  public static void copyDirectory(File srcPath, File dstPath)
      throws IOException
  {
    if (srcPath.isDirectory()) {
      if (!dstPath.exists()) {
        dstPath.mkdir();
      }

      String files[] = srcPath.list();
      for (int i = 0; i < files.length; i++) {
        copyDirectory(new File(srcPath, files[i]), new File(dstPath,
            files[i]));
      }
    } else {
      if (!srcPath.exists()) {
//        Log.d("Copy failure", "File or directory does not exist.");
      } else {
        InputStream in = new FileInputStream(srcPath);
        OutputStream out = new FileOutputStream(dstPath);

        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
          out.write(buf, 0, len);
        }
        in.close();
        out.close();
      }
    }
    System.out.println("Directory copied.");
  }

  public static void copy(File source, File target) throws IOException
  {

    InputStream in = new FileInputStream(source);
    OutputStream out = new FileOutputStream(target);

    // Copy the bits from instream to outstream
    byte[] buf = new byte[1024];
    int len;

    while ((len = in.read(buf)) > 0) {
      out.write(buf, 0, len);
    }

    in.close();
    out.close();
  }

  public static ArrayList<String> getImageNames(ProjectInfo project,
      Context cont)
  {
    String[] tempRes;
    
    String path = Environment.getExternalStorageDirectory()
        + "/Gui2Go/Projects/" + project.name + "/Images/";

    File f = new File(path);
    tempRes = f.list();
    return (convertStrArrayToList(tempRes));
  }
  
  public static ArrayList<String> convertStrArrayToList(String[] arr){
    ArrayList<String> res = new ArrayList<String>();
    for (int i = 0; i < arr.length; i++) {
      res.add(arr[i]);
    }
    return res;
  }

  public static void deleteImage(String resName, String projectName)
  {
    String path = Environment.getExternalStorageDirectory()
    + "/Gui2Go/Projects/" + projectName + "/Images/" + resName;
    File f = new File(path);
    if(f.exists()){
      f.delete();
    }
  }
}




Java Source Code List

com.ami.gui2go.ActivityManager.java
com.ami.gui2go.EditorActivity.java
com.ami.gui2go.FileDialogFragment.java
com.ami.gui2go.GridViewItemClickListener.java
com.ami.gui2go.HomeActivity.java
com.ami.gui2go.LongClickListener.java
com.ami.gui2go.ProjectManagerActivity.java
com.ami.gui2go.ResourceManagerActivity.java
com.ami.gui2go.UserGuideActivity.java
com.ami.gui2go.models.ActivityInfo.java
com.ami.gui2go.models.ProjectInfo.java
com.ami.gui2go.models.WidgetAttribute.java
com.ami.gui2go.models.WidgetTypes.java
com.ami.gui2go.models.WidgetWrapper.java
com.ami.gui2go.models.Widget.java
com.ami.gui2go.tree.AbstractTreeViewAdapter.java
com.ami.gui2go.tree.InMemoryTreeNode.java
com.ami.gui2go.tree.InMemoryTreeStateManager.java
com.ami.gui2go.tree.NodeAlreadyInTreeException.java
com.ami.gui2go.tree.NodeNotInTreeException.java
com.ami.gui2go.tree.SimpleStandardAdapter.java
com.ami.gui2go.tree.TreeBuilder.java
com.ami.gui2go.tree.TreeConfigurationException.java
com.ami.gui2go.tree.TreeNodeInfo.java
com.ami.gui2go.tree.TreeStateManager.java
com.ami.gui2go.tree.TreeViewList.java
com.ami.gui2go.utils.FileHelper.java
com.ami.gui2go.utils.LayoutXMLCreator.java
com.ami.gui2go.utils.ProjectXMLParser.java
com.ami.gui2go.utils.TextValidator.java
com.ami.gui2go.views.ColorPickerDialog.java