List of usage examples for android.graphics Rect height
public final int height()
From source file:com.lee.sdk.widget.viewpager.PointPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (null != mViewPager) { if (mViewPager instanceof CircularViewPager) { mPointCount = ((CircularViewPager) mViewPager).getCount(); } else {/*from www. j a v a 2 s . c om*/ mPointCount = mViewPager.getAdapter().getCount(); } } if (mPointCount <= 0) { return; } final int count = mPointCount; final int margin = mPointMargin; final int height = getHeight(); final int width = getWidth(); final int selIndex = mPosition; final Rect normalRc = mNormalPointRect; final Rect selectRc = mSelectPointRect; final Drawable dNormal = mNormalDrawable; final Drawable dSelect = mSelectDrawable; int left = (width - (margin * (count - 1) + normalRc.width() * (count - 1) + selectRc.width())) / 2; int top = 0; for (int index = 0; index < count; ++index) { if (index == selIndex) { if (null != dSelect) { top = (height - selectRc.height()) / 2; selectRc.offsetTo(left, top); dSelect.setBounds(selectRc); dSelect.draw(canvas); } left += (selectRc.width() + margin); } else { if (null != dNormal) { top = (height - normalRc.height()) / 2; normalRc.offsetTo(left, top); dNormal.setBounds(normalRc); dNormal.draw(canvas); } left += (normalRc.width() + margin); } } }
From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java
/** * Paints the data points of one series vertically. * * @param c canvas to paint to//from www. j a va 2 s.co m * @param nameBounds bounds of the label * @param seriesNo index of the series to paint * @param width width of the view * @param height height of the view * @param maxValue calculated possible maximum data value */ private void paintSeriesVertical(Canvas c, Rect nameBounds, int seriesNo, int width, @SuppressWarnings("UnusedParameters") int height, float maxValue) { float paddingLeft = getPaddingLeft(); float paddingTop = getPaddingTop(); float paddingRight = getPaddingRight(); float paddingBottom = getPaddingBottom(); float y = nameBounds.height() + paddingTop; float x; if (currentValue == -1) { x = (width - paddingLeft - paddingRight) / (seriesNames.length + 1) * (seriesNo + 1) + paddingLeft; } else { if (dataValues == null) { Log.e("Wa-Tor", "NO DATA VALUES although currentValue is " + currentValue); } else if (dataValues[currentValue] == null) { Log.e("Wa-Tor", "NO SERIES DATA although currentValue is " + currentValue); } x = dataValues[currentValue][seriesNo] * (width - paddingLeft - paddingRight) / maxValue + paddingLeft; } c.drawText(seriesNames[seriesNo], x - nameBounds.width() / 2, y, seriesPaints[seriesNo]); float scale = seriesPaints[seriesNo].getStrokeWidth(); y += 6f * scale; c.drawLine(x, y, x, y - 3f * scale, seriesPaints[seriesNo]); c.drawLine(x, y, x - 1.5f * scale, y - 1.5f * scale, seriesPaints[seriesNo]); c.drawLine(x, y, x + 1.5f * scale, y - 1.5f * scale, seriesPaints[seriesNo]); if (currentValue != -1) { int no = currentValue; do { if (dataValues[no] == null) { break; } float newX = dataValues[no][seriesNo] * (width - paddingLeft - paddingRight) / maxValue + paddingLeft; float newY = y + 1; c.drawLine(x, y, newX, newY, seriesPaints[seriesNo]); x = newX; y = newY; no = no == 0 ? dataValues.length - 1 : no - 1; } while (no != oldestValue && y < height - paddingBottom); } }
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
protected void constrainTranslation(Point translation, float scale) { int currentEdgeEffect = 0; if (scale <= 1) { finishEdgeEffect();//from w w w.java2s . c om return; } Rect originalBounds = mMasterImage.getOriginalBounds(); Matrix originalToScreen = mMasterImage.getImageToScreenMatrix(originalBounds.width(), originalBounds.height(), getWidth(), getHeight()); if (originalToScreen == null) { finishEdgeEffect(); return; } RectF screenPos = new RectF(originalBounds); originalToScreen.mapRect(screenPos); boolean rightConstraint = screenPos.right < getWidth(); boolean leftConstraint = screenPos.left > 0; boolean topConstraint = screenPos.top > 0; boolean bottomConstraint = screenPos.bottom < getHeight(); if (screenPos.width() > getWidth()) { if (rightConstraint && !leftConstraint) { float tx = screenPos.right - translation.x * scale; translation.x = (int) ((getWidth() - tx) / scale); currentEdgeEffect = EDGE_RIGHT; } else if (leftConstraint && !rightConstraint) { float tx = screenPos.left - translation.x * scale; translation.x = (int) ((-tx) / scale); currentEdgeEffect = EDGE_LEFT; } } else { float tx = screenPos.right - translation.x * scale; float dx = (getWidth() - screenPos.width()) / 2f; translation.x = (int) ((getWidth() - tx - dx) / scale); } if (screenPos.height() > getHeight()) { if (bottomConstraint && !topConstraint) { float ty = screenPos.bottom - translation.y * scale; translation.y = (int) ((getHeight() - ty) / scale); currentEdgeEffect = EDGE_BOTTOM; } else if (topConstraint && !bottomConstraint) { float ty = screenPos.top - translation.y * scale; translation.y = (int) ((-ty) / scale); currentEdgeEffect = EDGE_TOP; } } else { float ty = screenPos.bottom - translation.y * scale; float dy = (getHeight() - screenPos.height()) / 2f; translation.y = (int) ((getHeight() - ty - dy) / scale); } if (mCurrentEdgeEffect != currentEdgeEffect) { if (mCurrentEdgeEffect == 0 || currentEdgeEffect != 0) { mCurrentEdgeEffect = currentEdgeEffect; mEdgeEffect.finish(); } mEdgeEffect.setSize(getWidth(), mEdgeSize); } if (currentEdgeEffect != 0) { mEdgeEffect.onPull(mEdgeSize); } }
From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java
/** * This method is in charge of determining if the hover cell is above or below the bounds of the * listview. If so, the listview does an appropriate upward or downward smooth scroll so as to * reveal new items./* ww w . j a v a2s . com*/ */ protected boolean handleMobileCellScroll(Rect r) { int offset = computeVerticalScrollOffset(); int height = getHeight(); int extent = computeVerticalScrollExtent(); int range = computeVerticalScrollRange(); int hoverViewTop = r.top; int hoverHeight = r.height(); if (hoverViewTop <= 0 && offset > 0) { smoothScrollBy(-mSmoothScrollAmountAtEdge, 0); return true; } if (hoverViewTop + hoverHeight >= height && (offset + extent) < range) { smoothScrollBy(mSmoothScrollAmountAtEdge, 0); return true; } return false; }
From source file:com.google.blockly.android.ui.VirtualWorkspaceView.java
/** * Set scroll position for the {@link WorkspaceView} wrapped by this instance. * <p/>/*from w w w .j av a 2 s . c o m*/ * The given scroll position specifies the absolute offset of the displayed area within the * virtual workspace. Inside this method, the given scroll coordinates are clamped to their * valid ranges determined from the bounding box of all blocks in the virtual workspace, and * allowing for overscroll of half the width (or height, respectively) of this view. * * @param x The horizontal scroll position in pixel units of this view. * @param y The vertical scroll position in pixel units of this view. */ @Override public void scrollTo(int x, int y) { if (!mScrollable) { return; } // Clamp x and y to the scroll range that will allow for 1/2 the view (or more, for smaller // views) being outside the range use by blocks. This matches the computations in // computeHorizontalScrollOffset and computeVerticalScrollOffset, respectively. Rect blocksBounds = getViewScaledBlockBounds(); int blocksWidth = blocksBounds.width(); int blocksHeight = blocksBounds.height(); int viewWidth = getMeasuredWidth(); int halfViewWidth = viewWidth / 2; int viewHeight = getMeasuredHeight(); int halfViewHeight = viewHeight / 2; int horzMargin = halfViewWidth; // Default margin is half the scrollable view width. if (blocksWidth < halfViewWidth) { horzMargin = viewWidth - blocksWidth; } int vertMargin = halfViewHeight; if (blocksHeight < halfViewHeight) { vertMargin = viewHeight - blocksHeight; } final int xMin = blocksBounds.left - horzMargin; final int xMax = blocksBounds.right + horzMargin - viewWidth; x = clampToRange(x, xMin, xMax); final int yMin = blocksBounds.top - vertMargin; final int yMax = blocksBounds.bottom + vertMargin - viewHeight; y = clampToRange(y, yMin, yMax); // Update and show scroll bars. super.scrollTo(x, y); // Set view offset in the virtual workspace and request layout of the WorkspaceView with the // new offset. The view offset is the location of the top-left pixel displayed in this view // in virtual workspace coordinates, regardless of RTL vs. LTR mode. mWorkspaceView.getWorkspaceHelper().setVirtualWorkspaceViewOffset( (int) (x / mViewScale), /* virtual coords. */ (int) (y / mViewScale)); mWorkspaceView.requestLayout(); }
From source file:com.jafme.mobile.activity.CropImageActivity.java
private void done() { if (Network.isNetworkDisconnected(this)) { Toast.makeText(this, R.string.no_network_connection, Toast.LENGTH_SHORT).show(); return;// w w w .j a v a2 s . c o m } if (cropView == null || isSaving) return; isSaving = true; Bitmap croppedImage; Rect r = cropView.getScaledCropRect(sampleSize); int width = r.width(); int height = r.height(); int outWidth = width; int outHeight = height; if (maxX > 0 && maxY > 0 && (width > maxX || height > maxY)) { float ratio = (float) width / (float) height; if ((float) maxX / (float) maxY > ratio) { outHeight = maxY; outWidth = (int) ((float) maxY * ratio + .5f); } else { outWidth = maxX; outHeight = (int) ((float) maxX / ratio + .5f); } } try { croppedImage = decodeRegionCrop(r, outWidth, outHeight); } catch (IllegalArgumentException e) { setResultException(e); finish(); return; } if (croppedImage != null) { imageView.setImageRotateBitmapResetBase(new RotateBitmap(croppedImage, exifRotation), true); imageView.center(true, true); imageView.highlightViews.clear(); } saveImage(croppedImage); }
From source file:org.akop.crosswords.fragment.CrosswordFragment.java
@Override public void onCellLongPressed(CrosswordView view, Crossword.Word word, int cell) { // Get the highlighted cell's rectangle Rect rect = view.getCellRect(word, cell); // Offset the placeholder to the same position as the cell FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(rect.width(), rect.height()); lp.setMargins(rect.left, rect.top, 0, 0); mMenuPlaceholder.setLayoutParams(lp); // Save the word/cell associated with the popup mPopupWord = word;/* w w w . j ava2 s. c om*/ mPopupCell = cell; // Initialize and show the popup menu PopupMenu popup = new PopupMenu(getActivity(), mMenuPlaceholder); popup.setOnMenuItemClickListener(mCellPopupListener); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.fragment_crossword_popup_cell, popup.getMenu()); popup.show(); }
From source file:org.jraf.android.hellomundo.app.welcome.WelcomeActivity.java
private void setShowCasePosition(View view, Rect r) { Log.d("r=" + r); Rect rect = new Rect(r); if (rect.top > 0) { int margin = getResources().getDimensionPixelSize(R.dimen.welcome_showCase_margin); rect.inset(-margin, -margin);// w w w .j a v a 2 s. c o m } View imgShowCase = view.findViewById(R.id.imgShowCase); LayoutParams layoutParams = imgShowCase.getLayoutParams(); layoutParams.width = rect.width(); layoutParams.height = rect.height(); ((RelativeLayout.LayoutParams) layoutParams).topMargin = rect.top; ((RelativeLayout.LayoutParams) layoutParams).leftMargin = rect.left; imgShowCase.setLayoutParams(layoutParams); View imgShowCaseHide = view.findViewById(R.id.imgShowCase_hide); layoutParams = imgShowCaseHide.getLayoutParams(); layoutParams.width = rect.width(); layoutParams.height = rect.height(); ((RelativeLayout.LayoutParams) layoutParams).topMargin = rect.top; ((RelativeLayout.LayoutParams) layoutParams).leftMargin = rect.left; imgShowCaseHide.setLayoutParams(layoutParams); View imgAbove = view.findViewById(R.id.imgAbove); layoutParams = imgAbove.getLayoutParams(); layoutParams.height = rect.top; imgAbove.setLayoutParams(layoutParams); View imgLeft = view.findViewById(R.id.imgLeft); layoutParams = imgLeft.getLayoutParams(); layoutParams.width = rect.left; imgLeft.setLayoutParams(layoutParams); }
From source file:com.actionbarsherlock.internal.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }//from ww w . j av a2 s . c o m final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
From source file:org.immopoly.android.widget.ImmoscoutPlacesOverlay.java
/** * clusterize flats based on their supposed marker position *//*from www . j a v a 2s . com*/ public void clusterize() { if (mFlats == null) return; final Flats flats = mFlats; final ArrayList<ClusterItem> items = tmpItems; final Projection projection = mMapView.getProjection(); final Point screenPos = new Point(); items.clear(); // create tmp items with flat, geopoint & screenBounds for (int i = 0; i < flats.size(); i++) { final Flat flat = flats.get(i); if (flat.lat == 0 && flat.lng == 0 || !flat.visible) continue; Rect itemBounds = new Rect(markerBounds); GeoPoint point = new GeoPoint((int) (flat.lat * 1E6), (int) (flat.lng * 1E6)); projection.toPixels(point, screenPos); itemBounds.offset(screenPos.x, screenPos.y); items.add(new ClusterItem(flat, point, itemBounds)); } // join ClusterItems if their markers would intersect ArrayList<ClusterItem> newItems = new ArrayList<ClusterItem>(); final Rect intersection = new Rect(); final int size = items.size(); for (int i = 0; i < size; i++) { final ClusterItem item = (ClusterItem) items.get(i); if (item.consumed) continue; for (int j = i + 1; j < size; j++) { final ClusterItem otherItem = (ClusterItem) items.get(j); if (!otherItem.consumed && intersection.setIntersect(item.screenBounds, otherItem.screenBounds) && intersection.width() * intersection.height() >= MIN_INTERSECTION_AREA) item.add(otherItem); } newItems.add(item); } tmpItems.clear(); tmpItems.addAll(newItems); // see http://groups.google.com/group/android-developers/browse_thread/thread/38b11314e34714c3 setLastFocusedIndex(-1); populate(); }