List of usage examples for android.graphics Rect height
public final int height()
From source file:com.appunite.list.AbsHorizontalListView.java
/** * What is the distance between the source and destination rectangles given the direction of * focus navigation between them? The direction basically helps figure out more quickly what is * self evident by the relationship between the rects... * * @param source the source rectangle//from w ww .ja v a 2s .c o m * @param dest the destination rectangle * @param direction the direction * @return the distance between the rectangles */ static int getDistance(Rect source, Rect dest, int direction) { int sX, sY; // source x, y int dX, dY; // dest x, y switch (direction) { case View.FOCUS_RIGHT: sX = source.right; sY = source.top + source.height() / 2; dX = dest.left; dY = dest.top + dest.height() / 2; break; case View.FOCUS_DOWN: sX = source.left + source.width() / 2; sY = source.bottom; dX = dest.left + dest.width() / 2; dY = dest.top; break; case View.FOCUS_LEFT: sX = source.left; sY = source.top + source.height() / 2; dX = dest.right; dY = dest.top + dest.height() / 2; break; case View.FOCUS_UP: sX = source.left + source.width() / 2; sY = source.top; dX = dest.left + dest.width() / 2; dY = dest.bottom; break; case View.FOCUS_FORWARD: case View.FOCUS_BACKWARD: sX = source.right + source.width() / 2; sY = source.top + source.height() / 2; dX = dest.left + dest.width() / 2; dY = dest.top + dest.height() / 2; break; default: throw new IllegalArgumentException("direction must be one of " + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, " + "FOCUS_FORWARD, FOCUS_BACKWARD}."); } int deltaX = dX - sX; int deltaY = dY - sY; return deltaY * deltaY + deltaX * deltaX; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
/** * What is the distance between the source and destination rectangles given the direction of * focus navigation between them? The direction basically helps figure out more quickly what is * self evident by the relationship between the rects... * * @param source the source rectangle/* w w w . java 2 s .co m*/ * @param dest the destination rectangle * @param direction the direction * @return the distance between the rectangles */ private static int getDistance(Rect source, Rect dest, int direction) { int sX, sY; // source x, y int dX, dY; // dest x, y switch (direction) { case View.FOCUS_RIGHT: sX = source.right; sY = source.top + source.height() / 2; dX = dest.left; dY = dest.top + dest.height() / 2; break; case View.FOCUS_DOWN: sX = source.left + source.width() / 2; sY = source.bottom; dX = dest.left + dest.width() / 2; dY = dest.top; break; case View.FOCUS_LEFT: sX = source.left; sY = source.top + source.height() / 2; dX = dest.right; dY = dest.top + dest.height() / 2; break; case View.FOCUS_UP: sX = source.left + source.width() / 2; sY = source.top; dX = dest.left + dest.width() / 2; dY = dest.bottom; break; case View.FOCUS_FORWARD: case View.FOCUS_BACKWARD: sX = source.right + source.width() / 2; sY = source.top + source.height() / 2; dX = dest.left + dest.width() / 2; dY = dest.top + dest.height() / 2; break; default: throw new IllegalArgumentException("direction must be one of " + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, " + "FOCUS_FORWARD, FOCUS_BACKWARD}."); } int deltaX = dX - sX; int deltaY = dY - sY; return deltaY * deltaY + deltaX * deltaX; }
From source file:t3.giftbook.util.FlipViewPager.java
/** * ??/*w ww . j av a 2 s . c o m*/ */ private void drawFlippingPage(Canvas canvas) { if (mOffset == 0) { //?????????????Flip?????(draw??) return; } int scrollX = this.getScrollX(); if (currentPageBmp == null || currentPageBmp.isRecycled() || nextPageBmp.isRecycled()) { currentPageBmp = prepareBmp(canvas); currentPageCnv = new Canvas(currentPageBmp); nextPageBmp = prepareBmp(canvas); nextPageCnv = new Canvas(nextPageBmp); } if (currentPageBmp != null) { final int currentPage = mPosition; final int nextPage = currentPage + 1; if (currentPageCnv != null) { if (lastDrawedPage != currentPage) { try { //mPosition????????bounds???? //1???mOffset??????return. //???????????mPosition??????? final long time = System.currentTimeMillis(); drawChildTo(currentPageCnv, currentPage, time); drawChildTo(nextPageCnv, nextPage, time); //??currentPageBmp, nextPageBmp???????????? lastDrawedPage = currentPage; } catch (IllegalArgumentException e) { Log.w(TAG, e); } } } /* * canvas????????????? * ??????????? * ????????????? */ //? final Rect screenLeftSide = new Rect(scrollX, 0, scrollX + this.getWidth() / 2, this.getHeight()); //?? final Rect screenRightSide = new Rect(scrollX + this.getWidth() / 2, 0, scrollX + this.getWidth() / 1, this.getHeight()); //bmp? final Rect pageLeftSide = new Rect((int) (this.getWidth() * 0.0f), 0, (int) (this.getWidth() * 0.5f), this.getHeight()); //bmp?? final Rect pageRightSide = new Rect((int) (this.getWidth() * 0.5f), 0, (int) (this.getWidth() * 1.0f), this.getHeight()); /* * ???Flip?? */ //? Paint white = new Paint() { { this.setColor(Color.WHITE); } }; canvas.drawRect(screenLeftSide, white); canvas.drawRect(screenRightSide, white); //??????? canvas.drawBitmap(currentPageBmp, pageLeftSide, screenLeftSide, new Paint()); //???????? canvas.drawBitmap(nextPageBmp, pageRightSide, screenRightSide, new Paint()); // Paint shadow = new Paint() { { this.setColor(Color.BLACK); } }; final int meshCols = 30; final float meshColsf = (float) meshCols; final int meshRows = 30; final float meshRowsf = (float) meshRows; //?????????? if (mOffset <= 0.5) { final float offsetRate = (0.5f - mOffset) * 2; final float invOffsetRate = 1f - offsetRate; //??? shadow.setAlpha((int) (90 * offsetRate)); canvas.drawRect(screenRightSide, shadow); //??????????? final float[] rVerts = new float[(meshCols + 1) * (meshRows + 1) * 2]; for (int meshY = 0; meshY <= meshRows; meshY++) { final float meshYf = (float) meshY; for (int meshX = 0; meshX <= meshCols; meshX++) { final float meshXf = (float) meshX; final int meshPosition = (meshX + meshY * (meshCols + 1)) * 2; final int xPosition = meshPosition; final int yPosition = xPosition + 1; if (meshX <= meshCols / 2) { rVerts[xPosition] = screenRightSide.left; //?????????? rVerts[yPosition] = screenRightSide.top + screenRightSide.height() / meshRowsf * meshYf; } else { rVerts[xPosition] = screenRightSide.left + offsetRate * screenRightSide.width() / meshColsf * (meshXf - meshColsf / 2f) * 2f; rVerts[yPosition] = screenRightSide.top + screenRightSide.height() / 2f - screenRightSide.height() / meshRowsf * (meshRowsf / 2f - meshYf) * (1f + invOffsetRate / meshColsf * (meshXf - meshColsf / 2f)); } } } canvas.drawBitmapMesh(currentPageBmp, meshCols, meshRows, rVerts, 0, null, 0, null); //???? final Paint pageRootPaint = new Paint() { { int shadow1 = Color.argb((int) (30 * invOffsetRate), 0, 0, 0); int shadow2 = Color.argb(0, 0, 0, 0); this.setShader(new LinearGradient((float) screenRightSide.left, (float) screenRightSide.top + screenRightSide.height() / 2, (float) screenRightSide.left + screenRightSide.width() * offsetRate, (float) screenRightSide.top + screenRightSide.height() / 2, shadow1, shadow2, Shader.TileMode.CLAMP)); } }; canvas.drawRect(screenRightSide.left, screenRightSide.top, screenRightSide.right, screenRightSide.bottom, pageRootPaint); } else { final float offsetRate = (mOffset - 0.5f) * 2; final float invOffsetRate = 1f - offsetRate; //?? shadow.setAlpha((int) (90 * offsetRate)); canvas.drawRect(screenLeftSide, shadow); //???????? final float[] rVerts = new float[(meshCols + 1) * (meshRows + 1) * 2]; for (int meshY = 0; meshY <= meshRows; meshY++) { final float meshYf = (float) meshY; for (int meshX = 0; meshX <= meshCols; meshX++) { final float meshXf = (float) meshX; final float meshXfInv = meshColsf / 2f - meshXf; final int meshPosition = (meshX + meshY * (meshCols + 1)) * 2; final int xPosition = meshPosition; final int yPosition = xPosition + 1; if (meshX >= meshCols / 2) { rVerts[xPosition] = screenLeftSide.right; //??????????? rVerts[yPosition] = screenLeftSide.top + screenLeftSide.height() / meshRowsf * meshYf; } else { rVerts[xPosition] = screenLeftSide.right - offsetRate * screenLeftSide.width() + offsetRate * screenLeftSide.width() / meshColsf * (meshXf) * 2f; rVerts[yPosition] = screenLeftSide.top + screenLeftSide.height() / 2f - screenLeftSide.height() / meshRowsf * (meshRowsf / 2f - meshYf) * (1f + invOffsetRate / meshColsf * (meshColsf / 2f - meshXf)); } } } canvas.drawBitmapMesh(nextPageBmp, meshCols, meshRows, rVerts, 0, null, 0, null); //??? final Paint pageRootPaint = new Paint() { { int shadow2 = Color.argb((int) (30 * invOffsetRate), 0, 0, 0); int shadow1 = Color.argb(0, 0, 0, 0); this.setShader(new LinearGradient( (float) screenLeftSide.right - screenRightSide.width() * offsetRate, (float) screenLeftSide.top + screenRightSide.height() / 2, (float) screenLeftSide.right, (float) screenLeftSide.top + screenRightSide.height() / 2, shadow1, shadow2, Shader.TileMode.CLAMP)); } }; canvas.drawRect(screenLeftSide.left, screenLeftSide.top, screenLeftSide.right, screenLeftSide.bottom, pageRootPaint); } // int y = 0; // canvas.drawRect(0,0,canvas.getWidth(), 300, new Paint() {{this.setColor(Color.WHITE); this.setAlpha(100);}}); // Paint debugPrint = new Paint() {{this.setColor(Color.RED); this.setTextSize(30);}}; // canvas.drawText("b.width = " + bkbmp.getWidth() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("b.height = " + bkbmp.getHeight() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("c.width = " + canvas.getWidth() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("c.height = " + canvas.getHeight() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("scrollX = " + getScrollX() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mPosition = " + mPosition , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("lastPosition = " + lastDrawedPage , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mOffset = " + mOffset , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("offsetRate = " + offsetRate , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("invOffsetRate = " + invOffsetRate , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("mOffsetPixels = " + mOffsetPixels , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); // canvas.drawText("index = " + getCurrentItem() , scrollX, (++y) * debugPrint.getTextSize(), debugPrint); } }
From source file:com.appunite.list.AbsHorizontalListView.java
/** * Allows RemoteViews to scroll relatively to a position. *///from w w w.ja va2 s . c om void smoothScrollByOffset(int position) { int index = -1; if (position < 0) { index = getFirstVisiblePosition(); } else if (position > 0) { index = getLastVisiblePosition(); } if (index > -1) { View child = getChildAt(index - getFirstVisiblePosition()); if (child != null) { Rect visibleRect = new Rect(); if (child.getGlobalVisibleRect(visibleRect)) { // the child is partially visible int childRectArea = child.getWidth() * child.getHeight(); int visibleRectArea = visibleRect.width() * visibleRect.height(); float visibleArea = (visibleRectArea / (float) childRectArea); final float visibleThreshold = 0.75f; if ((position < 0) && (visibleArea < visibleThreshold)) { // the top index is not perceivably visible so offset // to account for showing that top index as well ++index; } else if ((position > 0) && (visibleArea < visibleThreshold)) { // the bottom index is not perceivably visible so offset // to account for showing that bottom index as well --index; } } smoothScrollToPosition(Math.max(0, Math.min(getCount(), index + position))); } } }
From source file:com.zoffcc.applications.zanavi.Navit.java
synchronized static int find_max_font_size_for_height(String sample_text, int height, int max_font_size, int padding_in_dp) { String s = sample_text;//from w w w .java 2 s . c om int bh = 0; Paint p = new Paint(); Rect bounds = new Rect(); p.setTextSize(max_font_size); // p.measureText(s); p.getTextBounds(s, 0, s.length(), bounds); int ret_font_size = max_font_size; int loop_counter_max = 400; int loop_counter = 0; int padding_in_px = 0; if (padding_in_dp > 0) { padding_in_px = NavitGraphics.dp_to_px(padding_in_dp); } bh = bounds.height(); //System.out.println("bh(1)=" + bh); while ((bh + padding_in_px) > height) { loop_counter++; if (loop_counter > loop_counter_max) { break; } ret_font_size--; p.setTextSize(ret_font_size); // p.measureText(s); p.getTextBounds(s, 0, s.length(), bounds); bh = bounds.height(); } return ret_font_size; }