Android Open Source - codemap Workspace Controller






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;
/* ww  w.  j a  va 2  s  .c  om*/
import java.io.IOException;
import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.PopupMenu;
import android.widget.Toast;

import com.hdweiss.codemap.data.CscopeEntry;
import com.hdweiss.codemap.data.ProjectController;
import com.hdweiss.codemap.util.CodeMapCursorPoint;
import com.hdweiss.codemap.util.CodeMapPoint;
import com.hdweiss.codemap.view.workspace.FindDeclarationTask.FindDeclarationCallback;
import com.hdweiss.codemap.view.workspace.fragments.CodeMapAnnotation;
import com.hdweiss.codemap.view.workspace.fragments.CodeMapFunction;
import com.hdweiss.codemap.view.workspace.fragments.CodeMapItem;
import com.hdweiss.codemap.view.workspace.fragments.CodeMapLink;
import com.hdweiss.codemap.view.workspace.outline.OutlineItem;

public class WorkspaceController extends ProjectController {

  private String workspaceName;
  public WorkspaceView codeMapView;

  public WorkspaceController(String projectName, String workspaceName, Context context) {
    super(projectName, context);
    this.workspaceName = workspaceName;
  }
  
  public void setView(WorkspaceView codeMapView) {
    this.codeMapView = codeMapView;
    this.codeMapView.setController(this);
    loadCodeMapState();
  }
  
  public String getWorkspaceName() {
    return this.workspaceName;
  }
   
  
    public void loadCodeMapState() {
      try {
      WorkspaceState state = WorkspaceState.readState(project, workspaceName, context);
      setState(state);
    } catch (IOException e) {
      e.printStackTrace();
      addAnnotationView("Welcome to CodeMap!\nYou can start browsing your project by using the explorer on the right.");
    }
    }
  
    @SuppressWarnings("unchecked")
  private void setState(WorkspaceState state) {
    if(state == null)
      return;
    
    WorkspaceStateLoader loadState = new WorkspaceStateLoader(state, codeMapView, this);
    loadState.execute(state.items);
    
    codeMapView.setScrollX(state.scrollX);
    codeMapView.setScrollY(state.scrollY);
    codeMapView.setScaleFactor(state.zoom, new CodeMapPoint());
  }
    
    
    public void saveCodeMapState() {
      try {
      codeMapView.getState().writeState(project, context);
    } catch (IOException e) {
      e.printStackTrace();
    }
    }
    
    
  public void addAnnotationView(String content) {
    if(codeMapView != null) {
      CodeMapPoint position = new CodeMapCursorPoint(100, 100).getCodeMapPoint(codeMapView);
      
      CodeMapAnnotation annotationView = new CodeMapAnnotation(codeMapView.getContext(),
          position, content);
      codeMapView.addMapItem(annotationView);
    }
  }
    
  public void addFileView(String fileName) {
    if(codeMapView != null) {
      CodeMapPoint position = new CodeMapCursorPoint(100, 100).getCodeMapPoint(codeMapView);
      final SpannableString content = getFileSource(fileName);
      
      CodeMapFunction functionView = new CodeMapFunction(codeMapView.getContext(),
          position, fileName, content);
      codeMapView.addMapItem(functionView);
    }
  }
  
    
  public void addFunctionView(String url) {
    if(codeMapView != null) {
      CodeMapPoint position = new CodeMapCursorPoint(100, 100).getCodeMapPoint(codeMapView);
      instantiateFunctionFragment(url, position);
    }
  }
  
  public int getOpenDeclarations(String url) {
    int numberOfDeclarations = codeMapView.getDeclarations(url).size();
    return numberOfDeclarations;
  }
  
  
  public void updateCodeBrowser() {
    Intent intent = new Intent(WorkspaceFragment.INTENT_REFRESH);
    context.sendBroadcast(intent);
  }
  
  public void updateWorkspaceBrowser() {
    Intent intent = new Intent(WorkspaceFragment.INTENT_REFRESH);
    intent.putExtra("action", "workspace");
    context.sendBroadcast(intent);
  }
  
  
  private static final int YScrollOffset = 200;
  private static final int XScrollOffset = 200;
  public void symbolClicked(String url, OutlineItem item) {
    ArrayList<CodeMapItem> declarations = codeMapView.getDeclarations(url);

    if (declarations.size() > 0) {
      int index = 0;
      if (item != null) {
        index = item.declarationCycle % declarations.size();
        item.declarationCycle++;
      }
      CodeMapItem codeMapItem = declarations.get(index);
      float x = codeMapItem.getX() - XScrollOffset;
      float y = codeMapItem.getY() - YScrollOffset;
      codeMapView.setScroll(x, y);
    } else
      addFunctionView(url);
  }

  
  private CodeMapFunction instantiateFunctionFragment(String url,
      CodeMapPoint position) throws IllegalArgumentException {
    CodeMapFunction functionView = new CodeMapFunction(codeMapView.getContext(),
        position, url, new SpannableString(""));
    codeMapView.addMapItem(functionView);
    
    new FindDeclarationTask(url, new SearchCallback(functionView), this,
        codeMapView.getContext()).execute();
    
    return functionView;
  }
  
  private class SearchCallback implements FindDeclarationCallback {
    private CodeMapFunction functionView;

    public SearchCallback(CodeMapFunction functionView) {
      this.functionView = functionView;
    }
    
    public void onSuccess(ArrayList<CscopeEntry> entries) {
      populateFragment(entries, functionView);
    }

    public void onFailure() {
      functionView.remove();
      Toast.makeText(context, "Error finding entries",
          Toast.LENGTH_SHORT).show();
    }
  }


  public void addChildFragmentFromUrl(String functionName, CodeMapItem parent, float yOffset) {
    float offset = yOffset + parent.getContentViewYOffset();

    CodeMapPoint position = new CodeMapPoint();
    position.x = parent.getX() + parent.getWidth() + 15;
    position.y = parent.getY() + offset;
    
    CodeMapFunction item = instantiateFunctionFragment(functionName,
        position);
    codeMapView.addMapItem(item);
    codeMapView.addMapLink(new CodeMapLink(parent, item, offset));
  }
  
  
  private void populateFragment(ArrayList<CscopeEntry> entries,
      CodeMapFunction functionView) {
    if (entries.size() > 1)
      showDeclarationPopup(entries, functionView);
    else if (entries.size() == 1) {
      CscopeEntry entry = entries.get(0);
      final SpannableString content = getFunctionSource(entry);
      functionView
          .init(entry.getActualUrl(project.getSourcePath(context)),
              content);
    }
  }

  private void showDeclarationPopup(final ArrayList<CscopeEntry> entries,
      final CodeMapFunction functionView) {
    PopupMenu popupMenu = new PopupMenu(context, functionView);

    for (int i = 0; i < entries.size(); i++) {
      CscopeEntry entry = entries.get(i);
      String url = entry.getUrl(project.getSourcePath(context));
      if (TextUtils.isEmpty(url) == false) {
        popupMenu.getMenu().add(Menu.NONE, i, Menu.NONE, url);
      }
    }

    popupMenu
        .setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            CscopeEntry entry = entries.get(item.getItemId());
            final SpannableString content = getFunctionSource(entry);
            String url = entry.getActualUrl(project
                .getSourcePath(context));
            functionView.init(url, content);
            return true;
          }

        });

    popupMenu.show();
  }
}




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