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:androidx.mediarouter.app.MediaRouteControllerDialog.java

/**
 * Updates the height of views and hide artwork or metadata if space is limited.
 *//*from w  w w. java2 s.  co m*/
void updateLayoutHeightInternal(boolean animate) {
    // Measure the size of widgets and get the height of main components.
    int oldHeight = getLayoutHeight(mMediaMainControlLayout);
    setLayoutHeight(mMediaMainControlLayout, ViewGroup.LayoutParams.MATCH_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:com.msn.support.gallery.ZoomActivity.java

/**
 * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in"
 * image view and animating its bounds to fit the entire activity content area. More
 * specifically://from ww  w  . ja v a2s .co  m
 * <ol>
 *   <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li>
 *   <li>Calculate the starting and ending bounds for the expanded view.</li>
 *   <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y)
 *       simultaneously, from the starting bounds to the ending bounds.</li>
 *   <li>Zoom back out by running the reverse animation on click.</li>
 * </ol>
 * ??ImageView?
 * Activity
 * <ol>
 *     <li>???ImageView</li>
 *     <li>?ImageView?</li>
 *     <li>??ImageView?/?X, Y, SCALE_X, SCALE_Y
 *     ??</li>
 *     <li>???</li>
 * @param thumbView  The thumbnail view to zoom in. 
 * @param imageResId The high-resolution version of the image represented by the thumbnail.
 *                   
 */
@TargetApi(11)
private void zoomImageFromThumb(final View thumbView, int imageResId) {
    // If there's an animation in progress, cancel it immediately and proceed with this one.
    // ?
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

    // Load the high-resolution "zoomed-in" image.?ImageView
    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);

    // Calculate the starting and ending bounds for the zoomed-in image. This step
    // involves lots of math. Yay, math.
    //?ImageView??
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    // The start bounds are the global visible rectangle of the thumbnail, and the
    // final bounds are the global visible rectangle of the container view. Also
    // set the container view's offset as the origin for the bounds, since that's
    // the origin for the positioning animation properties (X, Y).
    // ?????
    // ????
    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    Log.e("Test", "globalOffset.x=" + globalOffset.x + " globalOffset.y=" + globalOffset.y);
    Log.e("Test", "startBounds.top=" + startBounds.top + " startBounds.left=" + startBounds.left);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    Log.e("Test", "startBounds2.top=" + startBounds.top + " startBounds2.left=" + startBounds.left);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    // Adjust the start bounds to be the same aspect ratio as the final bounds using the
    // "center crop" technique. This prevents undesirable stretching during the animation.
    // Also calculate the start scaling factor (the end scaling factor is always 1.0).
    // ??"center crop"???
    // ????1.0
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        // Extend start bounds horizontally ?
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically ?
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    // Hide the thumbnail and show the zoomed-in view. When the animation begins,
    // it will position the zoomed-in view in the place of the thumbnail.
    //thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    // Construct and run the parallel animation of the four translation and scale properties
    // (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;

    // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
    // and show the thumbnail instead of the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}

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

@SuppressLint("DrawAllocation")
@Override//  w  w w  .j  a  v  a  2 s.  co  m
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;

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

        // Get model size
        mModelSize = (float) width / (float) mModels.size();

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

        mIconSize = 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 {
        // Disable vertical translation in coordinator layout
        mBehaviorEnabled = false;
        // Disable other features
        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.setBitmap(mBitmap);

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

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

    // Set titles canvas
    if (mIsTitled) {
        mTitlesBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        mTitlesCanvas.setBitmap(mTitlesBitmap);
    } else
        mTitlesBitmap = null;

    // 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 = 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);
    }

    //The translation behavior has to be set up after the super.onMeasure has been called
    if (!mIsBehaviorSet) {
        setBehaviorEnabled(mBehaviorEnabled);
        mIsBehaviorSet = true;
    }

    if (mBackground == null || mNeedInvalidateBackground) {
        if (getBackground() != null) {
            if (getBackground() instanceof BitmapDrawable)
                mBackground = ((BitmapDrawable) getBackground()).getBitmap();
            else {
                mBackground = Bitmap.createBitmap((int) mBounds.width(), (int) mBounds.height(),
                        Bitmap.Config.ARGB_8888);

                final Canvas backgroundCanvas = new Canvas(mBackground);
                getBackground().setBounds(0, 0, backgroundCanvas.getWidth(), backgroundCanvas.getHeight());
                getBackground().draw(backgroundCanvas);
            }

            setBackgroundDrawable(null);
            mNeedInvalidateBackground = false;
        }
    }
}

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@SuppressLint("DrawAllocation")
@Override/*from ww w. j  a  v a 2s.  c om*/
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;

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

        // Get model size
        mModelSize = (float) width / (float) mModels.size();

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

        mIconSize = side * (mIconSizeFraction != AUTO_SCALE ? mIconSizeFraction
                : (mIsTitled ? DEFAULT_TITLE_ICON_SIZE_FRACTION : DEFAULT_ICON_SIZE_FRACTION));
        if (mModelTitleSize == AUTO_SIZE)
            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) {
            if (mBadgeTitleSize == AUTO_SIZE)
                mBadgeTitleSize = (side * TITLE_SIZE_FRACTION) * 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 {
        // Disable vertical translation in coordinator layout
        mBehaviorEnabled = false;
        // Disable other features
        mIsHorizontalOrientation = false;
        mIsTitled = false;
        mIsBadged = false;

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

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

    final float barBadgeMargin = mBadgeGravity == BadgeGravity.TOP ? mBadgeMargin : 0.0F;
    mBgBounds.set(0.0F, barBadgeMargin, mBounds.width(), mBounds.height() + barBadgeMargin);

    // 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 = mIconSize / originalIconSize;
        model.mActiveIconScaleBy = model.mInactiveIconScale
                * (mIsTitled ? TITLE_ACTIVE_ICON_SCALE_BY : ACTIVE_ICON_SCALE_BY);
    }

    // Reset bitmap to init it onDraw()
    mBitmap = null;
    mPointerBitmap = null;
    mIconsBitmap = null;
    if (mIsTitled)
        mTitlesBitmap = null;

    // 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);
    }

    //The translation behavior has to be set up after the super.onMeasure has been called
    if (!mIsBehaviorSet) {
        setBehaviorEnabled(mBehaviorEnabled);
        mIsBehaviorSet = true;
    }
}

From source file:devlight.io.library.ntb.NavigationTabBar.java

@SuppressLint("DrawAllocation")
@Override/*from  ww  w  .j  ava 2s . c  o m*/
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;

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

        // Get model size
        mModelSize = (float) width / (float) mModels.size();

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

        mIconSize = side * (mIconSizeFraction != AUTO_SCALE ? mIconSizeFraction
                : (mIsTitled ? DEFAULT_TITLE_ICON_SIZE_FRACTION : DEFAULT_ICON_SIZE_FRACTION));
        if (mModelTitleSize == AUTO_SIZE)
            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) {
            if (mBadgeTitleSize == AUTO_SIZE)
                mBadgeTitleSize = (side * TITLE_SIZE_FRACTION) * 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 {
        // Disable vertical translation in coordinator layout
        mBehaviorEnabled = false;
        // Disable other features
        mIsHorizontalOrientation = false;
        //            mIsTitled = false;
        mIsBadged = false;

        mModelSize = (float) height / (float) mModels.size();
        // Get smaller side
        float side = mModelSize > width ? width : mModelSize;

        mIconSize = (int) (side
                * (mIconSizeFraction == AUTO_SCALE ? DEFAULT_ICON_SIZE_FRACTION : mIconSizeFraction));

        if (mModelTitleSize == AUTO_SIZE)
            mModelTitleSize = side * TITLE_SIZE_FRACTION;
        mTitleMargin = side * TITLE_MARGIN_FRACTION;
    }

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

    final float barBadgeMargin = mBadgeGravity == BadgeGravity.TOP ? mBadgeMargin : 0.0F;
    mBgBounds.set(0.0F, barBadgeMargin, mBounds.width(), mBounds.height() + barBadgeMargin);

    // 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 = mIconSize / originalIconSize;
        model.mActiveIconScaleBy = model.mInactiveIconScale
                * (mIsTitled ? TITLE_ACTIVE_ICON_SCALE_BY : SCALED_FRACTION);
    }

    // Reset bitmap to init it onDraw()
    mBitmap = null;
    mPointerBitmap = null;
    mIconsBitmap = null;
    if (mIsTitled)
        mTitlesBitmap = null;

    // 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);
    }

    //The translation behavior has to be set up after the super.onMeasure has been called
    if (!mIsBehaviorSet) {
        setBehaviorEnabled(mBehaviorEnabled);
        mIsBehaviorSet = true;
    }
}

From source file:org.androfarsh.widget.DragGridLayout.java

private boolean isSpaceFree(LayoutParams lp, Region freeRagion) {
    if (mCells.isEmpty() || (lp.mX == UNKNOWN) || (lp.mY == UNKNOWN)) {
        return false;
    }//from  www.  ja  va2s  .  com

    final Rect rect = new Rect(lp.leftMargin, lp.topMargin, (lp.mHorizontalSize * mCellSize) - lp.rightMargin,
            (lp.mVerticalSize * mCellSize) - lp.bottomMargin);
    rect.offset(lp.mX, lp.mY);

    mTmpRegion.set(freeRagion);
    mTmpRegion.op(rect, Op.INTERSECT);
    if (!mTmpRegion.isEmpty() && mTmpRegion.isRect()) {
        mTmpRegion.getBounds(mTmpRect);
        return ((mTmpRect.width() == rect.width()) && (mTmpRect.height() == rect.height()));
    }
    return false;
}

From source file:org.androfarsh.widget.DragGridLayout.java

public Cell findFreeCell(int rows, int cols, Region freeRegion) {
    if (mCells.isEmpty()) {
        return null;
    }/*from   w ww  .j a  va  2s.c o  m*/

    final Rect boundRect = new Rect();
    final Rect rect = new Rect(0, 0, cols * mCellSize, rows * mCellSize);

    for (final Cell cell : mCells) {
        mTmpRegion.set(freeRegion);
        rect.offsetTo(cell.rect.left, cell.rect.top);

        mTmpRegion.op(rect, Op.INTERSECT);
        if (!mTmpRegion.isEmpty() && mTmpRegion.isRect()) {
            mTmpRegion.getBounds(boundRect);
            if ((boundRect.width() == rect.width()) && (boundRect.height() == rect.height())) {
                return cell;
            }
        }
    }

    return null;
}

From source file:com.breakout.main.GameState.java

/**
 * Creates objects required to display a numeric score.
 *//*  www.  j  a v a2 s  .c o m*/
void allocScore() {
    /*
     * The score digits occupy a fixed position at the top right of the screen.  They're
     * actually part of the arena, and sit "under" the ball.  (We could, in fact, have the
     * ball collide with them.)
     *
     * We want to use fixed-size cells for the digits.  Each digit has a different width
     * though (which is somewhat true even if we use a monospace font -- a '1' can measure
     * narrower than an '8' because the text metrics ignore the padding).  We want to run
     * through and figure out what the widest glyph is, and use that as the cell width.
     *
     * The basic plan is to find the widest glyph, scale it up to match the height we
     * want, and use that as the size of a cell.  The digits are drawn scaled up to that
     * height, with the width increased proportionally (a given digit may not fill the
     * entire width of the cell).
     */

    int maxWidth = 0;
    Rect widest = null;
    for (int i = 0; i < 10; i++) {
        Rect boundsRect = mTextRes.getTextureRect(TextResources.DIGIT_START + i);
        int rectWidth = boundsRect.width();
        if (maxWidth < rectWidth) {
            maxWidth = rectWidth;
            widest = boundsRect;
        }
    }

    float widthHeightRatio = (float) widest.width() / widest.height();
    float cellHeight = ARENA_HEIGHT * SCORE_HEIGHT_PERC;
    float cellWidth = cellHeight * widthHeightRatio * 1.05f; // add 5% spacing between digits

    // Note these are laid out from right to left, i.e. mScoreDigits[0] is the 1s digit.
    for (int i = 0; i < NUM_SCORE_DIGITS; i++) {
        mScoreDigits[i] = new TexturedAlignedRect();
        mScoreDigits[i].setTexture(mTextRes.getTextureHandle(), mTextRes.getTextureWidth(),
                mTextRes.getTextureHeight());
        mScoreDigits[i].setPosition(SCORE_RIGHT - (i * cellWidth) - cellWidth / 2, SCORE_TOP - cellHeight / 2);
    }
}