Example usage for android.graphics Rect height

List of usage examples for android.graphics Rect height

Introduction

In this page you can find the example usage for android.graphics Rect height.

Prototype

public final int height() 

Source Link

Usage

From source file:com.juce.JuceAppActivity.java

public final int[] renderGlyph (char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds)
{
    Path p = new Path();
    paint.getTextPath (String.valueOf (glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds (boundsF, true);//from w  ww  .  j a v a 2s .c  o  m
    matrix.mapRect (boundsF);

    boundsF.roundOut (bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = Math.max (1, bounds.height());

    Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas (bm);
    matrix.postTranslate (-bounds.left, -bounds.top);
    c.setMatrix (matrix);
    c.drawPath (p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded)
        cachedRenderArray = new int [sizeNeeded];

    bm.getPixels (cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
}

From source file:com.android.leanlauncher.Workspace.java

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw/*from   w  w w.ja v a2s .com*/
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);
    }
    destCanvas.restore();
}

From source file:com.grottworkshop.gwsvectorsandboxlib.VectorDrawable.java

@Override
public void draw(Canvas canvas) {
    final Rect bounds = getBounds();
    if (bounds.width() == 0 || bounds.height() == 0) {
        // too small to draw
        return;/*from   w  w w.ja  v a2s. co m*/
    }

    final int saveCount = canvas.save();
    final boolean needMirroring = needMirroring();

    canvas.translate(bounds.left, bounds.top);
    if (needMirroring) {
        canvas.translate(bounds.width(), 0);
        canvas.scale(-1.0f, 1.0f);
    }

    // Color filters always override tint filters.
    final ColorFilter colorFilter = mColorFilter == null ? mTintFilter : mColorFilter;

    if (!mAllowCaching) {
        // AnimatedVectorDrawable
        if (!mVectorState.hasTranslucentRoot()) {
            mVectorState.mVPathRenderer.draw(canvas, bounds.width(), bounds.height(), colorFilter);
        } else {
            mVectorState.createCachedBitmapIfNeeded(bounds);
            mVectorState.updateCachedBitmap(bounds);
            mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter);
        }
    } else {
        // Static Vector Drawable case.
        mVectorState.createCachedBitmapIfNeeded(bounds);
        if (!mVectorState.canReuseCache()) {
            mVectorState.updateCachedBitmap(bounds);
            mVectorState.updateCacheStates();
        }
        mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter);
    }

    canvas.restoreToCount(saveCount);
}

From source file:com.gigamole.library.NavigationTabBar.java

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    // Get measure size
    final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int height = MeasureSpec.getSize(heightMeasureSpec);

    if (mModels.isEmpty() || width == 0 || height == 0)
        return;//from   ww  w. ja va2  s .  c o m

    // Detect orientation and calculate icon size
    if (width > height) {
        mIsHorizontalOrientation = true;

        // Get smaller side
        float side = mModelSize > height ? height : mModelSize;
        if (mIsBadged)
            side -= side * TITLE_SIZE_FRACTION;

        mModelSize = (float) width / (float) mModels.size();
        mIconSize = (int) (side * (mIsTitled ? TITLE_ICON_SIZE_FRACTION : ICON_SIZE_FRACTION));

        mModelTitleSize = side * TITLE_SIZE_FRACTION;
        mTitleMargin = side * TITLE_MARGIN_FRACTION;

        // If is badged mode, so get vars and set paint with default bounds
        if (mIsBadged) {
            mBadgeTitleSize = mModelTitleSize * BADGE_TITLE_SIZE_FRACTION;

            final Rect badgeBounds = new Rect();
            mBadgePaint.setTextSize(mBadgeTitleSize);
            mBadgePaint.getTextBounds(PREVIEW_BADGE, 0, 1, badgeBounds);
            mBadgeMargin = (badgeBounds.height() * 0.5f)
                    + (mBadgeTitleSize * BADGE_HORIZONTAL_FRACTION * BADGE_VERTICAL_FRACTION);
        }
    } else {
        mIsHorizontalOrientation = false;
        mIsTitled = false;
        mIsBadged = false;

        mModelSize = (float) height / (float) mModels.size();
        mIconSize = (int) ((mModelSize > width ? width : mModelSize) * ICON_SIZE_FRACTION);
    }

    // Set bounds for NTB
    mBounds.set(0.0f, 0.0f, width, height - mBadgeMargin);

    // Set main bitmap
    mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);

    // Set pointer canvas
    mPointerBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    mPointerCanvas = new Canvas(mPointerBitmap);

    // Set icons canvas
    mIconsBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    mIconsCanvas = new Canvas(mIconsBitmap);

    // Set scale fraction for icons
    for (Model model : mModels) {
        final float originalIconSize = model.mIcon.getWidth() > model.mIcon.getHeight() ? model.mIcon.getWidth()
                : model.mIcon.getHeight();
        model.mInactiveIconScale = (float) mIconSize / originalIconSize;
        model.mActiveIconScaleBy = model.mInactiveIconScale
                * (mIsTitled ? TITLE_ACTIVE_ICON_SCALE_BY : ACTIVE_ICON_SCALE_BY);
    }

    // Set start position of pointer for preview or on start
    if (isInEditMode() || !mIsViewPagerMode) {
        mIsSetIndexFromTabBar = true;

        // Set random in preview mode
        if (isInEditMode()) {
            mIndex = new Random().nextInt(mModels.size());

            if (mIsBadged)
                for (int i = 0; i < mModels.size(); i++) {
                    final Model model = mModels.get(i);

                    if (i == mIndex) {
                        model.mBadgeFraction = MAX_FRACTION;
                        model.showBadge();
                    } else {
                        model.mBadgeFraction = MIN_FRACTION;
                        model.hideBadge();
                    }
                }
        }

        mStartPointerX = mIndex * mModelSize;
        mEndPointerX = mStartPointerX;
        updateIndicatorPosition(MAX_FRACTION);
    }
}

From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java

/***
 * ?/*from   w ww  . ja  va  2 s. c o m*/
 * **/
private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:de.madvertise.android.sdk.MadvertiseView.java

/**
 * Draw the ad background for a text banner
 *
 * @param canvas//  w  w  w. j  av a2s .c  o m
 * @param rectangle
 * @param backgroundColor
 * @param mTextColor
 */
private void drawTextBannerBackground(final Canvas canvas, final Rect rectangle, final int backgroundColor,
        int shineColor) {
    Paint paint = new Paint();
    paint.setColor(backgroundColor);
    paint.setAntiAlias(true);
    canvas.drawRect(rectangle, paint);

    int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor),
            Color.blue(shineColor));
    int[] gradientColors = { upperColor, shineColor };
    GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            gradientColors);

    int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top;
    gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop);
    gradientDrawable.draw(canvas);

    Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom);
    Paint shadowPaint = new Paint();
    shadowPaint.setColor(shineColor);
    canvas.drawRect(shadowRect, shadowPaint);
}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(this, AnalyticsManager.SCREEN_SAMSUNG_SNOTE_EDITOR);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.snote_editor);
    context = this;

    // TOOLBAR//from   w w w  .j  a v  a 2s .  c o  m
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    // Retrieve information
    String action = getIntent().getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        if (getIntent().getData() != null) {
            String filePath = BaseActionUtils.getPath(this, getIntent().getData());
            file = new File(filePath);
        } else {
            AlfrescoNotificationManager.getInstance(this).showLongToast(getString(R.string.editor_error_open));
            finish();
            return;
        }
    }

    // Init Spen
    boolean isSpenFeatureEnabled = false;
    Spen spenPackage = new Spen();
    try {
        spenPackage.initialize(this);
        isSpenFeatureEnabled = spenPackage.isFeatureEnabled(Spen.DEVICE_PEN);
    } catch (SsdkUnsupportedException e) {
        if (SNoteUtils.processUnsupportedException(this, e)) {
            return;
        }
    } catch (Exception e1) {
        Log.e(TAG, Log.getStackTraceString(e1));
        finish();
    }

    FrameLayout spenViewContainer = (FrameLayout) findViewById(R.id.spenViewContainer);
    RelativeLayout spenViewLayout = (RelativeLayout) findViewById(R.id.spenViewLayout);

    // PEN SETTINGS
    spenSettingView = new SpenSettingPenLayout(context, "", spenViewLayout);
    if (spenSettingView == null) {
        finish();
    }
    spenViewContainer.addView(spenSettingView);

    // ERASER SETTINGS
    eraserSettingView = new SpenSettingEraserLayout(context, "", spenViewLayout);
    if (eraserSettingView == null) {
        finish();
    }
    spenViewContainer.addView(eraserSettingView);

    // TEXT SETTINGS
    textSettingView = new SpenSettingTextLayout(context, "", new HashMap<String, String>(), spenViewLayout);
    if (textSettingView == null) {
        finish();
    }
    spenViewContainer.addView(textSettingView);

    // SELECTION SETTINGS
    selectionSettingView = new SpenSettingSelectionLayout(context, "", spenViewLayout);
    if (textSettingView == null) {
        finish();
    }
    spenViewContainer.addView(selectionSettingView);

    // SURFACE VIEW
    spenSurfaceView = new SpenSurfaceView(context);
    if (spenSurfaceView == null) {
        finish();
    }
    spenViewLayout.addView(spenSurfaceView);
    spenSettingView.setCanvasView(spenSurfaceView);
    eraserSettingView.setCanvasView(spenSurfaceView);
    textSettingView.setCanvasView(spenSurfaceView);
    selectionSettingView.setCanvasView(spenSurfaceView);

    // NOTE DOCUMENT
    Display display = getWindowManager().getDefaultDisplay();
    Rect mScreenRect = new Rect();
    display.getRectSize(mScreenRect);
    try {
        if (file != null && file.length() > 0) {
            spenNoteDoc = new SpenNoteDoc(context, file.getAbsolutePath(), mScreenRect.width(),
                    SpenNoteDoc.MODE_WRITABLE);
            if (spenNoteDoc.getPageCount() == 0) {
                spenPageDoc = spenNoteDoc.appendPage();
            } else {
                spenPageDoc = spenNoteDoc.getPage(spenNoteDoc.getLastEditedPageIndex());
            }
        } else {
            spenNoteDoc = new SpenNoteDoc(context, SpenNoteDoc.ORIENTATION_LANDSCAPE,
                    (mScreenRect.width() > mScreenRect.height()) ? mScreenRect.width() : mScreenRect.height(),
                    (mScreenRect.width() < mScreenRect.height()) ? mScreenRect.width() : mScreenRect.height());
            spenPageDoc = spenNoteDoc.appendPage();
            spenPageDoc.setBackgroundColor(getResources().getColor(android.R.color.white));
            spenPageDoc.clearHistory();
        }
    } catch (Exception e) {
        finish();
    }

    // Display Document
    spenSurfaceView.setPageDoc(spenPageDoc, true);
    spenSurfaceView.setBlankColor(getResources().getColor(R.color.grey_light));

    if (!isSpenFeatureEnabled) {
        mToolType = SpenSurfaceView.TOOL_FINGER;
        spenSurfaceView.setToolTypeAction(mToolType, SpenSurfaceView.ACTION_STROKE);

        // Touch listener for swipe if on Finger mode
        gdt = new GestureDetector(context, new GestureListener());
        spenSurfaceView.setOnTouchListener(touchListener);
    }

    // Init Pages
    mTxtView = (TextView) findViewById(R.id.spen_page);
    mTxtView.setText(String.format(getString(R.string.editor_paging),
            String.valueOf((spenNoteDoc.getPageIndexById(spenPageDoc.getId()) + 1)),
            spenNoteDoc.getPageCount()));

    // INIT Setting & Listeners
    initSettingInfo();
    spenSurfaceView.setTouchListener(penTouchListener);
    spenSurfaceView.setControlListener(controlListener);
    spenSurfaceView.setFlickListener(mFlickListener);

}

From source file:com.facebook.litho.MountState.java

private static void mountItemIncrementally(MountItem item, Rect itemBounds, Rect localVisibleRect) {
    final Component<?> component = item.getComponent();

    if (!isMountViewSpec(component)) {
        return;//from w  w  w  .jav a2  s . c om
    }

    // We can't just use the bounds of the View since we need the bounds relative to the
    // hosting LithoView (which is what the localVisibleRect is measured relative to).
    final View view = (View) item.getContent();
    final Rect rect = ComponentsPools.acquireRect();
    rect.set(Math.max(0, localVisibleRect.left - itemBounds.left),
            Math.max(0, localVisibleRect.top - itemBounds.top),
            itemBounds.width() - Math.max(0, itemBounds.right - localVisibleRect.right),
            itemBounds.height() - Math.max(0, itemBounds.bottom - localVisibleRect.bottom));

    mountViewIncrementally(view, rect);

    ComponentsPools.release(rect);
}

From source file:talex.zsw.baselibrary.widget.NavigationTabBar.java

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    // Get measure size
    final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int height = MeasureSpec.getSize(heightMeasureSpec);

    if (mModels.isEmpty() || width == 0 || height == 0)
        return;//from  w ww .jav a  2s  . c  om

    // Detect orientation and calculate icon size
    if (width > height) {
        mIsHorizontalOrientation = true;

        // Get smaller side
        float side = mModelSize > height ? height : mModelSize;
        if (mIsBadged)
            side -= side * TITLE_SIZE_FRACTION;

        mModelSize = (float) width / (float) mModels.size();
        mIconSize = (int) (side * (mIsTitled ? TITLE_ICON_SIZE_FRACTION : ICON_SIZE_FRACTION));

        mModelTitleSize = side * TITLE_SIZE_FRACTION;
        mTitleMargin = side * TITLE_MARGIN_FRACTION;

        // If is badged mode, so get vars and set paint with default bounds
        if (mIsBadged) {
            mBadgeTitleSize = mModelTitleSize * BADGE_TITLE_SIZE_FRACTION;

            final Rect badgeBounds = new Rect();
            mBadgePaint.setTextSize(mBadgeTitleSize);
            mBadgePaint.getTextBounds(PREVIEW_BADGE, 0, 1, badgeBounds);
            mBadgeMargin = (badgeBounds.height() * 0.5f)
                    + (mBadgeTitleSize * BADGE_HORIZONTAL_FRACTION * BADGE_VERTICAL_FRACTION);
        }
    } else {
        mIsHorizontalOrientation = false;
        mIsTitled = false;
        mIsBadged = false;

        mModelSize = (float) height / (float) mModels.size();
        mIconSize = (int) ((mModelSize > width ? width : mModelSize) * ICON_SIZE_FRACTION);
    }

    // Set bounds for NTB
    mBounds.set(0.0f, 0.0f, width, height - mBadgeMargin);

    // Set main bitmap
    mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);

    // Set pointer canvas
    mPointerBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    mPointerCanvas = new Canvas(mPointerBitmap);

    // Set icons canvas
    mIconsBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    mIconsCanvas = new Canvas(mIconsBitmap);

    // Set scale fraction for icons
    for (Model model : mModels) {
        final float originalIconSize = model.mIcon.getWidth() > model.mIcon.getHeight() ? model.mIcon.getWidth()
                : model.mIcon.getHeight();
        model.mInactiveIconScale = (float) mIconSize / originalIconSize;
        model.mActiveIconScaleBy = model.mInactiveIconScale
                * (mIsTitled ? TITLE_ACTIVE_ICON_SCALE_BY : ACTIVE_ICON_SCALE_BY);
    }

    // Set start position of pointer for preview or on start
    if (isInEditMode() || !mIsViewPagerMode) {
        mIsSetIndexFromTabBar = true;

        // Set random in preview mode
        if (isInEditMode()) {
            mIndex = new Random().nextInt(mModels.size());

            if (mIsBadged) {
                for (int i = 0; i < mModels.size(); i++) {
                    final Model model = mModels.get(i);

                    if (i == mIndex) {
                        model.mBadgeFraction = MAX_FRACTION;
                        model.showBadge();
                    } else {
                        model.mBadgeFraction = MIN_FRACTION;
                        model.hideBadge();
                    }
                }
            }
        }

        mStartPointerX = mIndex * mModelSize;
        mEndPointerX = mStartPointerX;
        updateIndicatorPosition(MAX_FRACTION);
    }
}

From source file:cc.flydev.launcher.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);
    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;
    }/*from  w w w. j  a  v  a  2 s .  com*/
    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;
}