List of usage examples for android.graphics Rect width
public final int width()
From source file:com.pixby.texo.MainActivity.java
private void startSaveService(int folderLocation, int outputSizeFlag, int outputDestination) { String path = ImageUtil.getOutputFolder(this, mSourceImage.getFileName(), folderLocation); Rect outputSize = ImageUtil.calcTargetSize(mSourceImage.getWidth(), mSourceImage.getHeight(), outputSizeFlag);/* ww w .j a v a 2 s .c o m*/ Intent intent = new Intent(this, SaveImageService.class); intent.putExtra(SaveImageService.SOURCE_IMAGE_URI, mSourceImage.getUri()); intent.putExtra(SaveImageService.WATERMARK_JSON, mWatermark.toJson()); intent.putExtra(SaveImageService.OUTPUT_PATH, path); intent.putExtra(SaveImageService.OUTPUT_WIDTH, outputSize.width()); intent.putExtra(SaveImageService.OUTPUT_HEIGHT, outputSize.height()); intent.putExtra(SaveImageService.OUTPUT_DESTINATION, outputDestination); startService(intent); }
From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java
private void onSaveClicked() { if (cropView == null || isSaving) { return;// w ww . j a v a 2 s . co m } 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(); imageView.highlightViews.clear(); } saveImage(croppedImage); }
From source file:org.immopoly.android.widget.ImmoscoutPlacesOverlay.java
/** * clusterize flats based on their supposed marker position *///from w w w .j a v a2 s. co m 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(); }
From source file:org.mozilla.search.MainActivity.java
/** * Animates search suggestion to search bar. This animation has 2 main parts: * * 1) Vertically translate query text from suggestion card to search bar. * 2) Expand suggestion card to fill the results view area. * * @param query//from www . j av a 2s . co m * @param suggestionAnimation */ private void animateSuggestion(final String query, final SuggestionAnimation suggestionAnimation) { animationText.setText(query); final Rect startBounds = suggestionAnimation.getStartBounds(); final Rect endBounds = new Rect(); animationCard.getGlobalVisibleRect(endBounds, null); // Vertically translate the animated card to align with the start bounds. final float cardStartY = startBounds.centerY() - endBounds.centerY(); // Account for card background padding when calculating start scale. final float startScaleX = (float) (startBounds.width() - cardPaddingX * 2) / endBounds.width(); final float startScaleY = (float) (startBounds.height() - cardPaddingY * 2) / endBounds.height(); animationText.setVisibility(View.VISIBLE); animationCard.setVisibility(View.VISIBLE); final AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(animationText, "translationY", startBounds.top, textEndY), ObjectAnimator.ofFloat(animationCard, "translationY", cardStartY, 0), ObjectAnimator.ofFloat(animationCard, "alpha", 0.5f, 1), ObjectAnimator.ofFloat(animationCard, "scaleX", startScaleX, 1f), ObjectAnimator.ofFloat(animationCard, "scaleY", startScaleY, 1f)); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { setEditState(EditState.WAITING); setSearchState(SearchState.POSTSEARCH); editText.setText(query); // We need to manually clear the animation for the views to be hidden on gingerbread. animationText.clearAnimation(); animationCard.clearAnimation(); animationText.setVisibility(View.INVISIBLE); animationCard.setVisibility(View.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); set.setDuration(SUGGESTION_TRANSITION_DURATION); set.setInterpolator(SUGGESTION_TRANSITION_INTERPOLATOR); set.start(); }
From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java
/** * Sets the Drawables (if any) to appear to the left of, above, * to the right of, and below the text. Use null if you do not * want a Drawable there. The Drawables must already have had * {@link Drawable#setBounds} called./*from w w w .j av a 2s . com*/ * * @attr ref android.R.styleable#TextView_drawableLeft * @attr ref android.R.styleable#TextView_drawableTop * @attr ref android.R.styleable#TextView_drawableRight * @attr ref android.R.styleable#TextView_drawableBottom */ public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) { Drawables dr = mDrawables; final boolean drawables = left != null || top != null || right != null || bottom != null; if (!drawables) { // Clearing drawables... can we free the data structure? if (dr != null) { if (dr.mDrawablePadding == 0) { mDrawables = null; } else { // We need to retain the last set padding, so just clear // out all of the fields in the existing structure. dr.mDrawableLeft = null; dr.mDrawableTop = null; dr.mDrawableRight = null; dr.mDrawableBottom = null; dr.mDrawableSizeLeft = dr.mDrawableHeightLeft = 0; dr.mDrawableSizeRight = dr.mDrawableHeightRight = 0; dr.mDrawableSizeTop = dr.mDrawableWidthTop = 0; dr.mDrawableSizeBottom = dr.mDrawableWidthBottom = 0; } } } else { if (dr == null) { mDrawables = dr = new Drawables(); } dr.mDrawableLeft = left; dr.mDrawableTop = top; dr.mDrawableRight = right; dr.mDrawableBottom = bottom; final Rect compoundRect = dr.mCompoundRect; int[] state = null; state = mView.getDrawableState(); if (left != null) { left.setState(state); left.copyBounds(compoundRect); dr.mDrawableSizeLeft = compoundRect.width(); dr.mDrawableHeightLeft = compoundRect.height(); } else { dr.mDrawableSizeLeft = dr.mDrawableHeightLeft = 0; } if (right != null) { right.setState(state); right.copyBounds(compoundRect); dr.mDrawableSizeRight = compoundRect.width(); dr.mDrawableHeightRight = compoundRect.height(); } else { dr.mDrawableSizeRight = dr.mDrawableHeightRight = 0; } if (top != null) { top.setState(state); top.copyBounds(compoundRect); dr.mDrawableSizeTop = compoundRect.height(); dr.mDrawableWidthTop = compoundRect.width(); } else { dr.mDrawableSizeTop = dr.mDrawableWidthTop = 0; } if (bottom != null) { bottom.setState(state); bottom.copyBounds(compoundRect); dr.mDrawableSizeBottom = compoundRect.height(); dr.mDrawableWidthBottom = compoundRect.width(); } else { dr.mDrawableSizeBottom = dr.mDrawableWidthBottom = 0; } } mView.invalidate(); mView.requestLayout(); }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
/** * /*w w w .java 2s . co m*/ * @param canvas */ private void drawMonthTitle(Canvas canvas) { StringBuilder stringBuilder = new StringBuilder(getMonthAndYearString().toLowerCase()); stringBuilder.setCharAt(0, Character.toUpperCase(stringBuilder.charAt(0))); String text = stringBuilder.toString(); Rect rect = new Rect(); mMonthTitlePaint.getTextBounds(text, 0, text.length(), rect); // int x = (mWidth + 2 * mPadding) / 2; int leftPadding = getResources().getDimensionPixelSize(R.dimen.month_day_left_padding); int x = rect.width() / 2 + leftPadding; // int y = (MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE) / 2 + (MONTH_LABEL_TEXT_SIZE / 3); int y = (MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE) + (MONTH_LABEL_TEXT_SIZE / 4); if (mIsShowMonthDay) { y = MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE - (MONTH_LABEL_TEXT_SIZE * 2); } canvas.drawText(text, x, y, mMonthTitlePaint); int linePadding = getResources().getDimensionPixelSize(R.dimen.month_day_line_padding); canvas.drawLine(leftPadding, y + linePadding, rect.width() + leftPadding, y + linePadding, mMonthNumLinePaint); }
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 .jav a 2s .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.slushpupie.deskclock.DeskClock.java
private float fitTextToRect(Typeface font, String text, Rect fitRect) { int width = fitRect.width(); int height = fitRect.height(); int minGuess = 0; int maxGuess = 640; int guess = 320; Rect r;//from ww w.ja va 2s . c o m boolean lastGuessTooSmall = true; for (int i = 0; i < 32; i++) { if (minGuess + 1 == maxGuess) { Log.d(LOG_TAG, "Discovered font size " + minGuess); r = getBoundingBox(text, font, guess); return minGuess; } r = getBoundingBox(text, font, guess); if (r.width() > width || r.height() > height) { maxGuess = guess; lastGuessTooSmall = false; } else { minGuess = guess; lastGuessTooSmall = true; } guess = (minGuess + maxGuess) / 2; } Log.d(LOG_TAG, "Unable to discover font size"); if (lastGuessTooSmall) return maxGuess; else return minGuess; }
From source file:net.sf.fakenames.dispatcher.MaterialProgressDrawable.java
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); mWidth = bounds.width(); mHeight = bounds.height();// ww w . j a va2 s. co m invalidateSelf(); }
From source file:im.afterclass.android.fragment.ChatHistoryFragment.java
private void showRightPopupWindow(View v) { LayoutInflater inflater = LayoutInflater.from(getActivity()); View parent = getActivity().findViewById(R.id.main_button); View view = inflater.inflate(R.layout.half_popupwindow, null); String[] themes = new String[] { "?", "??", "" }; List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); for (int i = 0; i < themes.length; i++) { Map<String, Object> listItem = new HashMap<String, Object>(); listItem.put("theme", themes[i]); listItems.add(listItem);//from w w w .j av a 2 s .c o m } SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), listItems, R.layout.theme_simple_item, new String[] { "theme" }, new int[] { R.id.theme }); ListView themelist = (ListView) view.findViewById(R.id.themeListView); themelist.setAdapter(simpleAdapter); themelist.setOnItemClickListener(new ItemClickListener()); mPopupWindow = new PopupWindow(view); view.startAnimation(animSlideRightin); DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); int screenHeight = dm.heightPixels; int[] location = new int[2]; parent.getLocationInWindow(location); Rect frame = new Rect(); getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = frame.width(); mPopupWindow.setHeight(location[1] - getActivity().getActionBar().getHeight() - statusBarHeight); mPopupWindow.setWidth(width / 2); mPopupWindow.setTouchable(true); mPopupWindow.setFocusable(true); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.showAtLocation(getActivity().findViewById(R.id.main_bottom), Gravity.BOTTOM | Gravity.RIGHT, 0, screenHeight - location[1]); }