Android Open Source - codemap Collision Manager






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.j ava  2s  . c  o m
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;

import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;

import com.hdweiss.codemap.view.workspace.fragments.CodeMapItem;

public class CollisionManager {

  private static final int padding = 5;
  
  public static boolean pushItems(CodeMapItem pushingItem,
      ArrayList<CodeMapItem> items) {
    Log.d("Collision", "-> pushItems(): " + pushingItem.getUrl());  
    
    for (CodeMapItem item : items) {
      if (item == pushingItem)
        continue;

      Point pushOffset = getPushOffset(pushingItem.getBounds(),
          item.getBounds(), padding, true);
      
      if (pushOffset.equals(0, 0) == false) {
        item.push(pushOffset);
        Log.d("Collision", "pushItems(): pushed " + item.getUrl());  
        fixPush(item, new ArrayList<CodeMapItem>(items), pushOffset);
      }
    }

    return true;
  }
  
  private static void fixPush(CodeMapItem pushingItem,
      ArrayList<CodeMapItem> items, Point pushOffset) {
    items.remove(pushingItem);
    Iterator<CodeMapItem> iterator = items.iterator();
    
    while (iterator.hasNext()) {
      CodeMapItem item;
      try {
        item = iterator.next();
      } catch (ConcurrentModificationException e) {
        Log.e("Collision", "Collision manager caught ConcurrentModificationException");
        return;
      }
      if (pushingItem == item)
        continue;
      
      if (Rect.intersects(pushingItem.getBounds(), item.getBounds())) {
        Log.d("Collision", "fixPush(): " + pushingItem.getUrl() + " collided " + item.getUrl());
        item.push(pushOffset);
        iterator.remove();
        fixPush(item, items, pushOffset);
      }
    }
  }
  
  
  public static Point getPushOffset(Rect pusher, Rect pushed) {
    return getPushOffset(pusher, pushed, 0, true);
  }
  
  public static Point getPushOffset(Rect pusher, Rect pushed, int padding,
      boolean allowXPush) {
    if (Rect.intersects(pusher, pushed) == false)
      return new Point(0, 0);
    
    int pushUp = Math.abs(pusher.top - pushed.bottom);
    int pushDown = Math.abs(pusher.bottom - pushed.top);
    int pushRight = Math.abs(pusher.right - pushed.left);
    int pushLeft = Math.abs(pusher.left - pushed.right);
    
    int pushX;
    int pushY;
    
    if (pushUp < pushDown)
      pushY = -pushUp;
    else
      pushY = pushDown;
    
    if (pushLeft < pushRight)
      pushX = -pushLeft;
    else
      pushX = pushRight;
    
    if (pushX == 0 && pushY == 0)
      return new Point(0, 0);
    
    if (allowXPush && Math.abs(pushX) < Math.abs(pushY))
      return new Point(pushX + padding, 0);
    else
      return new Point(0, pushY + padding);
  }

}




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