// Rotates the bitmap by the specified degree. // If a new bitmap is created, the original bitmap is recycled. public static Bitmap rotateAndCrop(Bitmap b, int degrees, Rect crop) { if (b == null) return b; Bitmap b2 = null; int scale = Util.scalePow2(b.getHeight(), b.getWidth()); if (scale != 1 && crop != null) { crop.left *= scale; crop.right *= scale; crop.bottom *= scale; crop.top *= scale; } try { if (degrees != 0) { Matrix m = new Matrix(); m.setRotate(degrees, 0, 0); RectF r_rot = new RectF(0, 0, b.getWidth(), b.getHeight()); m.mapRect(r_rot); m.postTranslate(-r_rot.left, -r_rot.top); // r_rot.set(0,0,b.getWidth(),b.getHeight()); // m.mapRect(r_rot); // Log.d(TAG, "rotated bitmap = "+r_rot.toString()); if (crop == null) b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true); else { Matrix minv = new Matrix(); m.invert(minv); // minv.postScale(scale, scale); RectF r = new RectF(); r.set(crop); minv.mapRect(r); Log.d(TAG, "crop = " + crop.toString()); r.round(crop); Log.d(TAG, "bitmap " + b.getDensity() + " " + b.getWidth() + " x " + b.getHeight()); Log.d(TAG, "inv rotated crop = " + crop.toString()); b2 = Bitmap.createBitmap(b, crop.left, crop.top, crop.width(), crop.height(), m, true); } } else { if (crop != null) { Log.d(TAG, "crop = " + crop.toString()); Log.d(TAG, "bitmap " + b.getDensity() + " " + b.getWidth() + " x " + b.getHeight()); b2 = Bitmap.createBitmap(b, crop.left, crop.top, crop.width(), crop.height()); // b2 = Bitmap.createBitmap(b, scale*crop.left, scale*crop.top, // scale*crop.width(), scale*crop.height()); } else b2 = b; } } catch (OutOfMemoryError ex) { // We have no memory to rotate. Return the original bitmap. b2 = b; } Assert.assertNotNull(b2); if (b == b2) { return b; } else { Log.d(TAG, "b != b2, recycling b"); b.recycle(); return b2; } }
private static boolean isTouchInvalidArea(MotionEvent event, AmigoKeyguardPage mainCellLayout) { boolean isInvalidArea = false; Rect notificationRect = mainCellLayout.getNotificationContentRect(); if (DebugLog.DEBUG) DebugLog.d(TAG, "notificationRect: " + notificationRect.toString()); float x = event.getX(); float y = event.getY(); boolean isInNotificationRect = (x > notificationRect.left && x < notificationRect.right) && (y > notificationRect.top && y < notificationRect.bottom); if (isInNotificationRect) { isInvalidArea = true; } return isInvalidArea; }
/** * Print a tree to a specified stream. This method is intended for debugging. * * @param tree The tree to print * @param printStream The stream to which to print * @param prefix Any prefix that should be prepended to each line. */ @SuppressWarnings("unused") public static void printTree(OptionScanNode tree, PrintStream printStream, String prefix) { String treeClassName = tree.getClass().getSimpleName(); if (tree instanceof AccessibilityNodeActionNode) { Iterator<Rect> rects = tree.getRectsForNodeHighlight().iterator(); if (rects.hasNext()) { Rect rect = rects.next(); printStream.println(prefix + treeClassName + " with rect: " + rect.toString()); } return; } printStream.println(prefix + treeClassName); if (tree instanceof OptionScanSelectionNode) { OptionScanSelectionNode selectionNode = (OptionScanSelectionNode) tree; for (int i = 0; i < selectionNode.getChildCount(); ++i) { printTree(selectionNode.getChild(i), printStream, prefix + "-"); } } }
@Override public void onDraw(Canvas canvas, Rect bounds) { // Draw the background. Log.i("BuntinInfoBound", bounds.toString()); if (isInAmbientMode()) { canvas.drawColor(Color.BLACK); } else { canvas.drawRect(0, 0, bounds.width(), bounds.height(), mBackgroundPaint); } // Draw H:MM in ambient mode or H:MM:SS in interactive mode. mTime.setToNow(); String text = String.format("%d:%02d", mTime.hour, mTime.minute); // drawing time canvas.drawText(text, getCenterXCoordinate(mTextPaint, bounds, text), mYOffset, mTextPaint); text = getDate(mTime); // drawing date canvas.drawText( text, getCenterXCoordinate(mTextPaintDate, bounds, text), mYOffsetDate, mTextPaintDate); text = mHigh; float xCoordForTemp = 0; xCoordForTemp = getCenterXCoordinate(mTextPaintDate, bounds, text); // drawing high canvas.drawText(text, xCoordForTemp, mYOffsetTemp, mTextPaintDate); text = mLow; canvas.drawText(text, xCoordForTemp + 65, mYOffsetTemp, mTextPaintDate); Bitmap weatherImage = getWeatherImage(mWeatherImage); float imageXCoord = 0; imageXCoord = (xCoordForTemp - weatherImage.getWidth()); canvas.drawBitmap( weatherImage, imageXCoord, (mYOffsetTemp - weatherImage.getHeight() + 15), mTextPaintDate); }
public String toString() { return String.valueOf(mDayOfMonth) + "(" + mBound.toString() + ")"; }