List of usage examples for android.graphics Rect height
public final int height()
From source file:com.jjoe64.graphview.GridLabelRenderer.java
/** * calculates the horizontal label size/* w w w . ja va2 s. c om*/ * @param canvas canvas */ protected void calcLabelHorizontalSize(Canvas canvas) { // test label double testX = ((mGraphView.getViewport().getMaxX(false) - mGraphView.getViewport().getMinX(false)) * 0.783) + mGraphView.getViewport().getMinX(false); String testLabel = mLabelFormatter.formatLabel(testX, true); if (testLabel == null) { testLabel = ""; } Rect textBounds = new Rect(); mPaintLabel.getTextBounds(testLabel, 0, testLabel.length(), textBounds); mLabelHorizontalWidth = textBounds.width(); if (!mLabelHorizontalHeightFixed) { mLabelHorizontalHeight = textBounds.height(); // multiline int lines = 1; for (byte c : testLabel.getBytes()) { if (c == '\n') lines++; } mLabelHorizontalHeight *= lines; mLabelHorizontalHeight = (int) Math.max(mLabelHorizontalHeight, mStyles.textSize); } if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) { int adjHorizontalHeightH = (int) Math.round( Math.abs(mLabelHorizontalHeight * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle)))); int adjHorizontalHeightW = (int) Math.round( Math.abs(mLabelHorizontalWidth * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle)))); int adjHorizontalWidthH = (int) Math.round( Math.abs(mLabelHorizontalHeight * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle)))); int adjHorizontalWidthW = (int) Math.round( Math.abs(mLabelHorizontalWidth * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle)))); mLabelHorizontalHeight = adjHorizontalHeightH + adjHorizontalHeightW; mLabelHorizontalWidth = adjHorizontalWidthH + adjHorizontalWidthW; } // space between text and graph content mLabelHorizontalHeight += mStyles.labelsSpace; }
From source file:org.androfarsh.widget.DragGridLayout.java
private void requestDrop(Node node) { requestFreeCellRegion(node.view);/*from w ww . j a v a2 s . com*/ if (requestHoveredCells(node)) { requestHoverRect(mTmpRect); mTmpRegion.set(mFreeCellsRegion); mTmpRegion.op(mTmpRect, Op.INTERSECT); Rect bound = mTmpRegion.getBounds(); if (!mTmpRegion.isEmpty() && !mTmpRegion.isComplex() && (bound.width() == mTmpRect.width()) && (bound.height() == mTmpRect.height())) { node.startRect.offsetTo(mTmpRect.left, mTmpRect.top); return; } } final LayoutParams lp = (LayoutParams) node.view.getLayoutParams(); final LayoutParams newLp = validateLayoutParams(generateLayoutParams(lp), mFreeCellsRegion); if ((lp.mX == newLp.mX) && (lp.mY == newLp.mY)) { return; } node.startRect.offsetTo(newLp.mX, newLp.mY); }
From source file:com.wb.launcher3.Folder.java
private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getFolderHeight(); float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2); int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2); //*/modified by xuchao for folder fullscreen 20140513 int centeredLeft = (mLauncher.getWindowManager().getDefaultDisplay().getWidth() - width) / 2; int centeredTop = (mLauncher.getWindowManager().getDefaultDisplay().getHeight() - height) / 2; //*///from w w w .j av a 2 s . c o m int currentPage = mLauncher.getWorkspace().getNextPage(); // In case the workspace is scrolling, we need to use the final scroll to compute // the folders bounds. mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); // We first fetch the currently visible CellLayoutChildren CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We reset the workspaces scroll mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); // We need to bound the folder to the currently visible CellLayoutChildren int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) { // Center the folder if it is full (on phones only) left = (grid.availableWidthPx - width) / 2; } else if (width >= bounds.width()) { // If the folder doesn't fit within the bounds, center it about the desired bounds left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); setPivotX(folderPivotX); setPivotY(folderPivotY); mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); lp.width = width; lp.height = height; lp.x = left; lp.y = top; }
From source file:android.support.v7.app.MediaRouteControllerDialog.java
/** * Updates the height of views and hide artwork or metadata if space is limited. *//*from w w w . ja va 2s . co m*/ private void updateLayoutHeightInternal(boolean animate) { // Measure the size of widgets and get the height of main components. int oldHeight = getLayoutHeight(mMediaMainControlLayout); setLayoutHeight(mMediaMainControlLayout, ViewGroup.LayoutParams.FILL_PARENT); updateMediaControlVisibility(canShowPlaybackControlLayout()); View decorView = getWindow().getDecorView(); decorView.measure(MeasureSpec.makeMeasureSpec(getWindow().getAttributes().width, MeasureSpec.EXACTLY), MeasureSpec.UNSPECIFIED); setLayoutHeight(mMediaMainControlLayout, oldHeight); int artViewHeight = 0; if (mCustomControlView == null && mArtView.getDrawable() instanceof BitmapDrawable) { Bitmap art = ((BitmapDrawable) mArtView.getDrawable()).getBitmap(); if (art != null) { artViewHeight = getDesiredArtHeight(art.getWidth(), art.getHeight()); mArtView.setScaleType(art.getWidth() >= art.getHeight() ? ImageView.ScaleType.FIT_XY : ImageView.ScaleType.FIT_CENTER); } } int mainControllerHeight = getMainControllerHeight(canShowPlaybackControlLayout()); int volumeGroupListCount = mGroupMemberRoutes.size(); // Scale down volume group list items in landscape mode. int expandedGroupListHeight = getGroup() == null ? 0 : mVolumeGroupListItemHeight * getGroup().getRoutes().size(); if (volumeGroupListCount > 0) { expandedGroupListHeight += mVolumeGroupListPaddingTop; } expandedGroupListHeight = Math.min(expandedGroupListHeight, mVolumeGroupListMaxHeight); int visibleGroupListHeight = mIsGroupExpanded ? expandedGroupListHeight : 0; int desiredControlLayoutHeight = Math.max(artViewHeight, visibleGroupListHeight) + mainControllerHeight; Rect visibleRect = new Rect(); decorView.getWindowVisibleDisplayFrame(visibleRect); // Height of non-control views in decor view. // This includes title bar, button bar, and dialog's vertical padding which should be // always shown. int nonControlViewHeight = mDialogAreaLayout.getMeasuredHeight() - mDefaultControlLayout.getMeasuredHeight(); // Maximum allowed height for controls to fit screen. int maximumControlViewHeight = visibleRect.height() - nonControlViewHeight; // Show artwork if it fits the screen. if (mCustomControlView == null && artViewHeight > 0 && desiredControlLayoutHeight <= maximumControlViewHeight) { mArtView.setVisibility(View.VISIBLE); setLayoutHeight(mArtView, artViewHeight); } else { if (getLayoutHeight(mVolumeGroupList) + mMediaMainControlLayout.getMeasuredHeight() >= mDefaultControlLayout.getMeasuredHeight()) { mArtView.setVisibility(View.GONE); } artViewHeight = 0; desiredControlLayoutHeight = visibleGroupListHeight + mainControllerHeight; } // Show the playback control if it fits the screen. if (canShowPlaybackControlLayout() && desiredControlLayoutHeight <= maximumControlViewHeight) { mPlaybackControlLayout.setVisibility(View.VISIBLE); } else { mPlaybackControlLayout.setVisibility(View.GONE); } updateMediaControlVisibility(mPlaybackControlLayout.getVisibility() == View.VISIBLE); mainControllerHeight = getMainControllerHeight(mPlaybackControlLayout.getVisibility() == View.VISIBLE); desiredControlLayoutHeight = Math.max(artViewHeight, visibleGroupListHeight) + mainControllerHeight; // Limit the volume group list height to fit the screen. if (desiredControlLayoutHeight > maximumControlViewHeight) { visibleGroupListHeight -= (desiredControlLayoutHeight - maximumControlViewHeight); desiredControlLayoutHeight = maximumControlViewHeight; } // Update the layouts with the computed heights. mMediaMainControlLayout.clearAnimation(); mVolumeGroupList.clearAnimation(); mDefaultControlLayout.clearAnimation(); if (animate) { animateLayoutHeight(mMediaMainControlLayout, mainControllerHeight); animateLayoutHeight(mVolumeGroupList, visibleGroupListHeight); animateLayoutHeight(mDefaultControlLayout, desiredControlLayoutHeight); } else { setLayoutHeight(mMediaMainControlLayout, mainControllerHeight); setLayoutHeight(mVolumeGroupList, visibleGroupListHeight); setLayoutHeight(mDefaultControlLayout, desiredControlLayoutHeight); } // Maximize the window size with a transparent layout in advance for smooth animation. setLayoutHeight(mExpandableAreaLayout, visibleRect.height()); rebuildVolumeGroupList(animate); }
From source file:org.jraf.android.piclabel.app.form.FormActivity.java
private void drawText(Canvas canvas) { Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true);/* ww w . j av a2 s . c o m*/ paint.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/" + getSelectedFontName())); int textSize = canvas.getHeight() / 35; paint.setTextSize(textSize); int margin = textSize / 5; // Measure date/time String dateTime = mEdtDateTime.getText().toString(); Rect boundsDateTime = new Rect(); paint.getTextBounds(dateTime, 0, dateTime.length(), boundsDateTime); // Measure location String location = mEdtLocation.getText().toString(); Rect boundsLocation = new Rect(); paint.getTextBounds(location, 0, location.length(), boundsLocation); int totalWidth = boundsDateTime.width() + textSize * 2 + boundsLocation.width(); if (totalWidth > canvas.getWidth()) { // Draw on 2 lines // Draw a rectangle paint.setColor(Color.argb(180, 0, 0, 0)); canvas.drawRect(0, 0, canvas.getWidth(), -boundsDateTime.top + boundsDateTime.bottom + -boundsLocation.top + boundsLocation.bottom + margin * 3, paint); // Draw date/time paint.setColor(Color.WHITE); canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint); // Draw location canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin, margin + -boundsDateTime.top + boundsDateTime.bottom + margin + -boundsLocation.top, paint); } else { // Draw on 1 line // Draw a rectangle paint.setColor(Color.argb(180, 0, 0, 0)); canvas.drawRect(0, 0, canvas.getWidth(), margin + Math.max(boundsDateTime.height(), boundsLocation.height()) + margin, paint); // Draw date/time paint.setColor(Color.WHITE); canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint); // Draw location canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin, margin + -boundsLocation.top, paint); } }
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
protected float getVerticalCenterTextPosition(float originalYPosition, String text, Paint textPaint) { Rect bounds = new Rect(); textPaint.getTextBounds(text, 0, text.length(), bounds); return originalYPosition + (bounds.height() / 2); }
From source file:org.androfarsh.widget.DragGridLayout.java
private Cell findCellUnder(Rect rect) { Cell resCell = null;/* w w w.ja v a 2s . c o m*/ final Rect resRect = new Rect(); for (final Cell cell : mCells) { if (mTmpRect.setIntersect(cell.rect, rect)) { if ((resCell == null) || ((mTmpRect.width() * mTmpRect.height()) > (resRect.width() * resRect.height()))) { resRect.set(mTmpRect); resCell = cell; } } } return resCell; }
From source file:com.example.SmartBoard.DrawingView.java
public boolean onTouchDragEvent(MotionEvent event) { boolean handled = false; JSONObject mObjectTouched;/*from w w w . j av a 2 s . c o m*/ int X; int Y; int pointerId; int actionIndex = event.getActionIndex(); //get coordinates and make object transparent switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: dragFinished = false; //it's the first pointer, so clear all existing pointers data mObjectPointers.clear(); X = (int) event.getX(actionIndex); Y = (int) event.getY(actionIndex); dragX = X; dragY = Y; String objectType = ""; //check if we've touched inside some object mObjectTouched = getTouchedObject(X, Y); if (mObjectTouched == null) { return true; } else { objectType = getObjectType(mObjectTouched); } if (objectType.compareTo("Circle") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); } catch (JSONException e) { e.printStackTrace(); } } else if (objectType.compareTo("Rectangle") == 0) { Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens")); tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height()); try { mObjectTouched.put("dimens", tempRect.flattenToString()); } catch (JSONException e) { } } else if (objectType.compareTo("Line") == 0) { if (lengthOfLine(X, Y, mObjectTouched.optInt("startx"), mObjectTouched.optInt("starty")) < lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy"))) { try { mObjectTouched.put("startx", X); mObjectTouched.put("starty", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy"))); } catch (JSONException e) { e.printStackTrace(); } dragLineStart = true; } else { try { mObjectTouched.put("stopx", X); mObjectTouched.put("stopy", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"), mObjectTouched.optInt("starty"))); } catch (JSONException e) { e.printStackTrace(); } dragLineStart = false; } } else if (objectType.compareTo("Text") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region")); tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y); mObjectTouched.put("region", tempRect.flattenToString()); } catch (JSONException e) { e.printStackTrace(); } } mObjectPointers.put(event.getPointerId(0), mObjectTouched); if (mObjectTouched != null) { mqtt.publishObject(mObjectTouched); } invalidate(); handled = true; break; case MotionEvent.ACTION_POINTER_DOWN: break; case MotionEvent.ACTION_MOVE: dragFinished = false; final int pointerCount = event.getPointerCount(); for (actionIndex = 0; actionIndex < pointerCount; actionIndex++) { //some pointer has moved, search it by pointer id pointerId = event.getPointerId(actionIndex); X = (int) event.getX(actionIndex); Y = (int) event.getY(actionIndex); dragX = X; dragY = Y; mObjectTouched = mObjectPointers.get(pointerId); if (mObjectTouched == null) continue; // if null no object was touched so skip if (mObjectTouched.optString("type").compareTo("Circle") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); } catch (JSONException e) { } } else if (mObjectTouched.optString("type").compareTo("Rectangle") == 0) { Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens")); tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height()); try { mObjectTouched.put("dimens", tempRect.flattenToString()); } catch (JSONException e) { } } else if (mObjectTouched.optString("type").compareTo("Text") == 0) { try { mObjectTouched.put("x", X); mObjectTouched.put("y", Y); Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region")); tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y); mObjectTouched.put("region", tempRect.flattenToString()); } catch (JSONException e) { e.printStackTrace(); } } else if (mObjectTouched.optString("type").compareTo("Line") == 0) { if (dragLineStart) { try { mObjectTouched.put("startx", X); mObjectTouched.put("starty", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy"))); //mObjectTouched.put("stopx", tempStopX); // mObjectTouched.put("stopy", tempStopY); } catch (JSONException e) { e.printStackTrace(); } } else { try { mObjectTouched.put("stopx", X); mObjectTouched.put("stopy", Y); mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"), mObjectTouched.optInt("starty"))); //mObjectTouched.put("stopx", tempStopX); // mObjectTouched.put("stopy", tempStopY); } catch (JSONException e) { e.printStackTrace(); } } } if (mObjectTouched != null) { mqtt.publishObject(mObjectTouched); } } invalidate(); handled = true; break; case MotionEvent.ACTION_UP: dragFinished = true; mObjectPointers.clear(); invalidate(); handled = true; break; case MotionEvent.ACTION_CANCEL: handled = true; break; default: // do nothing break; } return super.onTouchEvent(event) || handled; }
From source file:com.fairphone.fplauncher3.Folder.java
private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getFolderHeight(); float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2); int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; int currentPage = mLauncher.getWorkspace().getNextPage(); // In case the workspace is scrolling, we need to use the final scroll to compute // the folders bounds. mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); // We first fetch the currently visible CellLayoutChildren CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); if (currentLayout == null) { return;/*from www . j a v a 2 s . c o m*/ } ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We reset the workspaces scroll mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); // We need to bound the folder to the currently visible CellLayoutChildren int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) { // Center the folder if it is full (on phones only) left = (grid.availableWidthPx - width) / 2; } else if (width >= bounds.width()) { // If the folder doesn't fit within the bounds, center it about the desired bounds left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); setPivotX(folderPivotX); setPivotY(folderPivotY); mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); lp.width = width; lp.height = height; lp.x = left; lp.y = top; }
From source file:com.breakout.main.GameState.java
/** * Draws the current score.//from w w w .j a va 2 s.com */ void drawScore() { float cellHeight = ARENA_HEIGHT * SCORE_HEIGHT_PERC; int score = mScore; for (int i = 0; i < NUM_SCORE_DIGITS; i++) { int val = score % 10; Rect boundsRect = mTextRes.getTextureRect(TextResources.DIGIT_START + val); float ratio = cellHeight / boundsRect.height(); TexturedAlignedRect scoreCell = mScoreDigits[i]; scoreCell.setTextureCoords(boundsRect); scoreCell.setScale(boundsRect.width() * ratio, cellHeight); scoreCell.draw(); score /= 10; } }