Android Open Source - codemap Workspace State






From Project

Back to project page codemap.

License

The source code is released under:

GNU General Public License

If you think the Android project codemap 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.hdweiss.codemap.view.workspace;
/*  w ww.  java 2s  .c  o  m*/
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;

import android.content.Context;

import com.hdweiss.codemap.data.Project;
import com.hdweiss.codemap.data.ProjectController;
import com.hdweiss.codemap.data.SerializableItem;
import com.hdweiss.codemap.data.SerializableLink;
import com.hdweiss.codemap.util.Utils;

public class WorkspaceState implements Serializable {
  private static final long serialVersionUID = 4L;
  
  public String workspaceName;

  public ArrayList<SerializableItem> items = new ArrayList<SerializableItem>();
  public ArrayList<SerializableLink> links = new ArrayList<SerializableLink>();

  public int scrollX = 0;
  public int scrollY = 0;
  public float zoom = 1;


  public WorkspaceState(String workspaceName) {
    this.workspaceName = workspaceName;
  }
  
  public void writeState(Project project, Context context) throws IOException {
    byte[] serializeObject = Utils.serializeObject(this);
    
    FileOutputStream fos = new FileOutputStream(getStateFile(project, workspaceName, context));
    fos.write(serializeObject);
    fos.close();
  }

  public static WorkspaceState readState(Project project, String workspaceName, Context context)
      throws IOException {
    FileInputStream fis = new FileInputStream(getStateFile(project, workspaceName, context));
    byte[] serializedObject = new byte[fis.available()];
    fis.read(serializedObject);
    fis.close();

    WorkspaceState result = (WorkspaceState) Utils.deserializeObject(serializedObject);
    return result;
  }

  private static File getStateFile(Project project, String workspaceName, Context context)
      throws FileNotFoundException {
    return new File(getStateFilePath(project, workspaceName, context));
  }
  
  private static String getStateFilePath (Project project, String workspace, Context context) {
    File directory = project.getProjectDirectory(context);
    return directory.getAbsolutePath() + File.separator + workspace + ".state";
  }
  
  public static ArrayList<String> getWorkspaceStateList(ProjectController controller, Context context) {
    ArrayList<String> result = new ArrayList<String>();
        
    String[] fileList = controller.project.getProjectDirectory(context)
        .list();
    
    for(String filename: fileList) {
      if(filename.endsWith(".state")) {
        String projectName = filename.substring(0, filename.length()
            - ".state".length());
        result.add(projectName);
      }
    }

    return result;
  }  

  public static void deleteState(String projectName, Context context) {
    File directory = Project.getProjectDirectory(projectName, context);
    
    File[] toBeDeleted = directory.listFiles(new FileFilter() {
      public boolean accept(File theFile) {
        if (theFile.isFile()) {
          return theFile.getName().endsWith(".state");
        }
        return false;
      }
    });

    for (File deletableFile : toBeDeleted) {
      deletableFile.delete();
    }
  }
  
  
}




Java Source Code List

com.hdweiss.codemap.data.CodeMapApp.java
com.hdweiss.codemap.data.CscopeEntry.java
com.hdweiss.codemap.data.CscopeWrapper.java
com.hdweiss.codemap.data.Cscope.java
com.hdweiss.codemap.data.ICodeMapItem.java
com.hdweiss.codemap.data.JGitWrapper.java
com.hdweiss.codemap.data.ProjectController.java
com.hdweiss.codemap.data.Project.java
com.hdweiss.codemap.data.SerializableItem.java
com.hdweiss.codemap.data.SerializableLink.java
com.hdweiss.codemap.util.AbsoluteLayout.java
com.hdweiss.codemap.util.CodeMapCursorPoint.java
com.hdweiss.codemap.util.CodeMapPoint.java
com.hdweiss.codemap.util.FlowLayout.java
com.hdweiss.codemap.util.ObjectSerializer.java
com.hdweiss.codemap.util.SpanUtils.java
com.hdweiss.codemap.util.SyntaxHighlighter.java
com.hdweiss.codemap.util.Utils.java
com.hdweiss.codemap.util.ZoomableAbsoluteLayout.java
com.hdweiss.codemap.util.ZoomableLinearLayout.java
com.hdweiss.codemap.view.CodeMapActivity.java
com.hdweiss.codemap.view.CodeMapTabListener.java
com.hdweiss.codemap.view.Preferences.java
com.hdweiss.codemap.view.project.ProjectAdapter.java
com.hdweiss.codemap.view.project.ProjectBrowser.java
com.hdweiss.codemap.view.project.ProjectItemView.java
com.hdweiss.codemap.view.project.ProjectWizard.java
com.hdweiss.codemap.view.workspace.CollisionManager.java
com.hdweiss.codemap.view.workspace.FindDeclarationTask.java
com.hdweiss.codemap.view.workspace.WorkspaceController.java
com.hdweiss.codemap.view.workspace.WorkspaceFragment.java
com.hdweiss.codemap.view.workspace.WorkspaceStateLoader.java
com.hdweiss.codemap.view.workspace.WorkspaceState.java
com.hdweiss.codemap.view.workspace.WorkspaceViewListeners.java
com.hdweiss.codemap.view.workspace.WorkspaceView.java
com.hdweiss.codemap.view.workspace.browser.WorkspaceBrowserAdapter.java
com.hdweiss.codemap.view.workspace.browser.WorkspaceBrowser.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapAnnotation.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapFunction.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapImage.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapItem.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapLink.java
com.hdweiss.codemap.view.workspace.fragments.FunctionLinkSpan.java
com.hdweiss.codemap.view.workspace.outline.CscopeEntryAdapter.java
com.hdweiss.codemap.view.workspace.outline.OutlineAdapter.java
com.hdweiss.codemap.view.workspace.outline.OutlineBrowser.java
com.hdweiss.codemap.view.workspace.outline.OutlineItemComparator.java
com.hdweiss.codemap.view.workspace.outline.OutlineItemView.java
com.hdweiss.codemap.view.workspace.outline.OutlineItem.java