Java Code Examples for android.graphics.Rect#sort()

The following examples show how to use android.graphics.Rect#sort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwitchAccessNodeCompat.java    From talkback with Apache License 2.0 6 votes vote down vote up
private void reduceVisibleRectangleForWindowsAbove(Rect visibleRect) {
  Trace.beginSection("SwitchAccessNodeCompat#reduceVisibleRectangleForWindowsAbove");
  Rect windowBoundsInScreen = new Rect();
  int visibleRectWidth = visibleRect.right - visibleRect.left;
  int visibleRectHeight = visibleRect.bottom - visibleRect.top;
  for (int i = 0; i < windowsAbove.size(); ++i) {
    windowsAbove.get(i).getBoundsInScreen(windowBoundsInScreen);
    windowBoundsInScreen.sort();
    Rect intersectingRectangle = new Rect(visibleRect);
    if (intersectingRectangle.intersect(windowBoundsInScreen)) {
      // If the rect above occupies less than a fraction of both sides of this rect, don't
      // adjust this rect's bounds. This prevents things like FABs changing the bounds
      // of scroll views under them.
      if (((intersectingRectangle.right - intersectingRectangle.left)
              < (visibleRectWidth * MIN_INTERSECTION_TO_CROP))
          && ((intersectingRectangle.bottom - intersectingRectangle.top)
              < (visibleRectHeight * MIN_INTERSECTION_TO_CROP))) {
        Trace.endSection();
        return;
      }
      adjustRectToAvoidIntersection(visibleRect, windowBoundsInScreen);
    }
  }
  Trace.endSection();
}
 
Example 2
Source File: GLES20Canvas.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
    Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
    Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
    bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
    bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
    bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
    bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
    bounds.sort();
}
 
Example 3
Source File: DividerItemDecoration.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
private void drawDivider(Canvas canvas, View view, Rect rect) {
    Drawable divider = this.mDivider;
    divider.setAlpha((int) (view.getAlpha() * 255f * mDividerAlpha));
    rect.sort();
    divider.setBounds(rect);
    divider.draw(canvas);
}
 
Example 4
Source File: GLES20Canvas.java    From android-openGL-canvas with Apache License 2.0 5 votes vote down vote up
@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
    Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
    Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
    bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
    bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
    bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
    bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
    bounds.sort();
}
 
Example 5
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
    Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
    Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
    bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
    bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
    bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
    bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
    bounds.sort();
}
 
Example 6
Source File: GLES20Canvas.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
    Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
    Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
    bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
    bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
    bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
    bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
    bounds.sort();
}
 
Example 7
Source File: SwitchAccessNodeCompat.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Find the largest sub-rectangle that doesn't intersect a specified one.
 *
 * @param rectToModify The rect that may be modified to avoid intersections
 * @param otherRect The rect that should be avoided
 */
private static void adjustRectToAvoidIntersection(Rect rectToModify, Rect otherRect) {
  /*
   * Some rectangles are flipped around (left > right). Make sure we have two Rects free of
   * such pathologies.
   */
  rectToModify.sort();
  otherRect.sort();
  /*
   * Intersect rectToModify with four rects that represent cuts of the entire space along
   * lines defined by the otherRect's edges
   */
  Rect[] cuts = {
    new Rect(Integer.MIN_VALUE, Integer.MIN_VALUE, otherRect.left, Integer.MAX_VALUE),
    new Rect(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, otherRect.top),
    new Rect(otherRect.right, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE),
    new Rect(Integer.MIN_VALUE, otherRect.bottom, Integer.MAX_VALUE, Integer.MAX_VALUE)
  };

  int maxIntersectingRectArea = 0;
  int indexOfLargestIntersection = -1;
  for (int i = 0; i < cuts.length; i++) {
    if (cuts[i].intersect(rectToModify)) {
      /* Reassign this cut to its intersection with rectToModify */
      int visibleRectArea = cuts[i].width() * cuts[i].height();
      if (visibleRectArea > maxIntersectingRectArea) {
        maxIntersectingRectArea = visibleRectArea;
        indexOfLargestIntersection = i;
      }
    }
  }
  if (maxIntersectingRectArea <= 0) {
    // The rectToModify isn't within any of our cuts, so it's entirely occluded by otherRect.
    rectToModify.setEmpty();
    return;
  }
  rectToModify.set(cuts[indexOfLargestIntersection]);
}
 
Example 8
Source File: SwitchAccessNodeCompat.java    From talkback with Apache License 2.0 5 votes vote down vote up
private void updateVisibility(int currentDepth) {
  if (visibilityAndSpokenTextCalculated || (currentDepth > MAX_DEPTH)) {
    return;
  }
  PerformanceMonitor.getOrCreateInstance()
      .startNewTimerEvent(TreeBuildingEvent.SCREEN_VISIBILITY_UPDATE);
  visibleBoundsInScreen = new Rect();
  if (!isOnScreenAndVisibleToUser()) {
    visibleBoundsInScreen.setEmpty();
    PerformanceMonitor.getOrCreateInstance()
        .stopTimerEvent(TreeBuildingEvent.SCREEN_VISIBILITY_UPDATE, false);
    return;
  }

  Trace.beginSection("SwitchAccessNodeCompat#updateVisibility (when visible to user)");
  getBoundsInScreen(visibleBoundsInScreen);
  visibleBoundsInScreen.sort();

  // Deal with visibility implications from windows above. However, do not update visibility for
  // sibling views as we cannot do so robustly. Notably, while we have drawing order, that is not
  // enough as views can be transparent and let touches through.
  reduceVisibleRectangleForWindowsAbove(visibleBoundsInScreen);

  PerformanceMonitor.getOrCreateInstance()
      .stopTimerEvent(TreeBuildingEvent.SCREEN_VISIBILITY_UPDATE, false);
  visibilityAndSpokenTextCalculated = true;
  Trace.endSection();
}
 
Example 9
Source File: TreeScanSystemProvidedNode.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isProbablyTheSameAs(Object other) {
  // Consider Views as likely the same if they have the same
  // 1) View ids
  // 2) Either their top or bottom bounds
  // 3) Either their right or left bounds
  // This is important to be able to keep focus on a text box whose size increases as text is
  // added.
  TreeScanSystemProvidedNode otherNode = (TreeScanSystemProvidedNode) other;
  Rect bounds = getBoundsInScreen();
  Rect otherBounds = otherNode.getBoundsInScreen();
  bounds.sort();
  otherBounds.sort();
  if (((bounds.top != otherBounds.top) && (bounds.bottom != otherBounds.bottom))
      || ((bounds.right != otherBounds.right) && (bounds.left != otherBounds.left))) {
    return false;
  }
  SwitchAccessNodeCompat firstNode = getNodeInfoCompatDirectly();
  SwitchAccessNodeCompat otherFirstNode = otherNode.getNodeInfoCompatDirectly();
  String viewIdResourceName = firstNode.getViewIdResourceName();
  boolean sameResourceId =
      (viewIdResourceName != null)
          && viewIdResourceName.equals(otherFirstNode.getViewIdResourceName());
  if (sameResourceId) {
    return true;
  }

  return hasSimilarText(otherNode);
}
 
Example 10
Source File: GLES20Canvas.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
    Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
    Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
    Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
    bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
    bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
    bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
    bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
    bounds.sort();
}
 
Example 11
Source File: Numberbox2.java    From PdDroidPublisher with GNU General Public License v3.0 4 votes vote down vote up
public Numberbox2(PdDroidPatchView app, String[] atomline) {
	super(app);
	
	float x = Float.parseFloat(atomline[2]) ;
	float y = Float.parseFloat(atomline[3]) ;
	Rect tRect = new Rect();
	
	// calculate screen bounds for the numbers that can fit
	numwidth = Integer.parseInt(atomline[5]);
	StringBuffer calclen = new StringBuffer();
	for (int s=0; s<numwidth; s++) {
		if (s == 1) {
			calclen.append(".");
		} else {
			calclen.append("#");
		}
	}
	fmt = new DecimalFormat(calclen.toString());
	paint.getTextBounds(calclen.toString(), 0, calclen.length(), tRect);
	tRect.sort();
	
	float h = Float.parseFloat(atomline[6]) ;
	
	dRect.left = x;
	dRect.top = y;
	dRect.bottom = y + h;
	dRect.right = x + h/2 + tRect.width();
	
	min = Float.parseFloat(atomline[7]);
	max = Float.parseFloat(atomline[8]);
	init = Integer.parseInt(atomline[10]);
	sendname = app.replaceDollarZero(atomline[11]);
	receivename = atomline[12];
	label = setLabel(atomline[13]);
	labelpos[0] = Float.parseFloat(atomline[14]) ;
	labelpos[1] = Float.parseFloat(atomline[15]) ;
	
	// set the value to the init value if possible
	setval(Float.parseFloat(atomline[21]), 0);
	
	// listen out for floats from Pd
	setupreceive();
	
	// send initial value if we have one
	initval();
}
 
Example 12
Source File: Symbol.java    From PdDroidPublisher with GNU General Public License v3.0 4 votes vote down vote up
public Symbol(PdDroidPatchView app, String[] atomline) 
{
	super(app);
	
	float x = Float.parseFloat(atomline[2]) ;
	float y = Float.parseFloat(atomline[3]) ;
	
	// calculate screen bounds for the numbers that can fit
	numChars = Integer.parseInt(atomline[4]);
	StringBuffer calclen = new StringBuffer();
	for (int s=0; s<numChars; s++) {
			calclen.append("W");
	}
	
	Rect tRect = new Rect();
	paint.getTextBounds(calclen.toString(), 0, calclen.length(), tRect);
	tRect.sort();
	
	float w = tRect.width();
	float h = tRect.height() + 6; // XXX margin v
	
	dRect.left = x;
	dRect.top = y;
	dRect.bottom = y + h;
	dRect.right = x + w;
	
	min = Float.parseFloat(atomline[5]);
	max = Float.parseFloat(atomline[6]);
	sendname = app.replaceDollarZero(atomline[10]);
	receivename = atomline[9];
	if(sendname.endsWith(",")) sendname = sendname.substring(0, sendname.length()-1);
	label = setLabel(atomline[8]);
	
	if(label != null)
	{
		labelPosition = Integer.parseInt(atomline[7]);
		
		Rect labelRect = new Rect();
		paint.getTextBounds(label, 0, label.length(), labelRect);
		
		float marging = 2; // XXX magic number
		
		labelpos[0] = 0; 
		labelpos[1] = 0;
		switch(labelPosition)
		{
		case POSITION_RIGHT:
			labelpos[0] = dRect.width() + marging;
			labelpos[1] = dRect.height()/2;
			break;
		case POSITION_LEFT:
			labelpos[0] = -labelRect.width() - marging - 2; // XXX
			labelpos[1] = dRect.height()/2;
			break;
		case POSITION_BOTTOM:
			labelpos[1] = dRect.height() - paint.ascent()/2 + marging;
			break;
		case POSITION_TOP:
			labelpos[1] = -labelRect.height() - marging;
			break;
		}
	}
	
	background.load(TAG, "back", label, sendname, receivename);
	
	setval(0, 0);
	
	// listen out for floats from Pd
	setupreceive();
}
 
Example 13
Source File: RectUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Find the largest sub-rectangle that doesn't intersect a specified one. <strong>Note:</strong>
 * {@code rectToModify} and {@code otherRect} will be sorted after operation.
 *
 * @param rectToModify The rect that may be modified to avoid intersections
 * @param otherRect The rect that should be avoided
 */
public static void adjustRectToAvoidIntersection(Rect rectToModify, Rect otherRect) {
  /*
   * Some rectangles are flipped around (left > right). Make sure we have two Rects free of
   * such pathologies.
   */
  rectToModify.sort();
  otherRect.sort();

  if (rectToModify.contains(otherRect) || !Rect.intersects(rectToModify, otherRect)) {
    return;
  }

  /*
   * Intersect rectToModify with four rects that represent cuts of the entire space along
   * lines defined by the otherRect's edges
   */
  Rect[] cuts = {
    new Rect(rectToModify.left, rectToModify.top, otherRect.left, rectToModify.bottom),
    new Rect(rectToModify.left, rectToModify.top, rectToModify.right, otherRect.top),
    new Rect(otherRect.right, rectToModify.top, rectToModify.right, rectToModify.bottom),
    new Rect(rectToModify.left, otherRect.bottom, rectToModify.right, rectToModify.bottom)
  };

  int maxIntersectingRectArea = 0;
  int indexOfLargestIntersection = -1;
  for (int i = 0; i < cuts.length; i++) {
    if (!isSorted(cuts[i])) {
      continue;
    }
    if (Rect.intersects(cuts[i], rectToModify)) {
      /* Reassign this cut to its intersection with rectToModify */
      int visibleRectArea = cuts[i].width() * cuts[i].height();
      if (visibleRectArea > maxIntersectingRectArea) {
        maxIntersectingRectArea = visibleRectArea;
        indexOfLargestIntersection = i;
      }
    }
  }
  if (maxIntersectingRectArea <= 0) {
    // The rectToModify isn't within any of our cuts, so it's entirely occuled by otherRect.
    rectToModify.setEmpty();
    return;
  }
  rectToModify.set(cuts[indexOfLargestIntersection]);
}