Example usage for android.graphics Rect width

List of usage examples for android.graphics Rect width

Introduction

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

Prototype

public final int width() 

Source Link

Usage

From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java

private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
    // Release memory now
    clearImageView();//w w  w  . j  a va 2s . c  o m

    InputStream is = null;
    Bitmap croppedImage = null;
    try {
        is = getContentResolver().openInputStream(sourceUri);
        BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false);
        final int width = decoder.getWidth();
        final int height = decoder.getHeight();

        if (exifRotation != 0) {
            // Adjust crop area to account for image rotation
            Matrix matrix = new Matrix();
            matrix.setRotate(-exifRotation);

            RectF adjusted = new RectF();
            matrix.mapRect(adjusted, new RectF(rect));

            //if the cutting box are rectangle( outWidth != outHeight ),and the exifRotation is 90 or 270,
            //the outWidth and outHeight showld be interchanged
            if (exifRotation == 90 || exifRotation == 270) {
                int temp = outWidth;
                outWidth = outHeight;
                outHeight = temp;
            }

            // Adjust to account for origin at 0,0
            adjusted.offset(adjusted.left < 0 ? width : 0, adjusted.top < 0 ? height : 0);
            rect = new Rect((int) adjusted.left, (int) adjusted.top, (int) adjusted.right,
                    (int) adjusted.bottom);
        }

        try {
            croppedImage = decoder.decodeRegion(rect, new BitmapFactory.Options());
            if (rect.width() > outWidth || rect.height() > outHeight) {
                Matrix matrix = new Matrix();
                matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height());

                //if the picture's exifRotation !=0 ,they should be rotate to 0 degrees
                matrix.postRotate(exifRotation);
                croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(),
                        croppedImage.getHeight(), matrix, true);
            } else {
                //if the picture need not to be scale, they also neet to be rotate to 0 degrees
                Matrix matrix = new Matrix();
                matrix.postRotate(exifRotation);
                croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(),
                        croppedImage.getHeight(), matrix, true);
            }
        } catch (IllegalArgumentException e) {
            // Rethrow with some extra information
            throw new IllegalArgumentException("Rectangle " + rect + " is outside of the image (" + width + ","
                    + height + "," + exifRotation + ")", e);
        }

    } catch (IOException e) {
        Log.e("Error cropping image: " + e.getMessage(), e);
        finish();
    } catch (OutOfMemoryError e) {
        Log.e("OOM cropping image: " + e.getMessage(), e);
        setResultException(e);
    } finally {
        CropUtil.closeSilently(is);
    }
    return croppedImage;
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * As the name means./*from  ww w.  ja v a  2  s  . c o m*/
 */
private void buildAddressBar(final Uri path) {
    if (path == null)
        return;

    mViewAddressBar.removeAllViews();

    new LoadingDialog<Void, Cursor, Void>(getActivity(), false) {

        LinearLayout.LayoutParams lpBtnLoc;
        LinearLayout.LayoutParams lpDivider;
        LayoutInflater inflater = getLayoutInflater(null);
        final int dim = getResources().getDimensionPixelSize(R.dimen.afc_5dp);
        int count = 0;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            lpBtnLoc = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            lpBtnLoc.gravity = Gravity.CENTER;
        }// onPreExecute()

        @Override
        protected Void doInBackground(Void... params) {
            Cursor cursor = getActivity().getContentResolver().query(path, null, null, null, null);
            while (cursor != null) {
                if (cursor.moveToFirst()) {
                    publishProgress(cursor);
                    cursor.close();
                } else
                    break;

                /*
                 * Process the parent directory.
                 */
                Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(BaseFile.COLUMN_URI)));
                cursor = getActivity().getContentResolver()
                        .query(BaseFile.genContentUriApi(uri.getAuthority()).buildUpon()
                                .appendPath(BaseFile.CMD_GET_PARENT)
                                .appendQueryParameter(BaseFile.PARAM_SOURCE, uri.getLastPathSegment()).build(),
                                null, null, null, null);
            } // while

            return null;
        }// doInBackground()

        @Override
        protected void onProgressUpdate(Cursor... progress) {
            /*
             * Add divider.
             */
            if (mViewAddressBar.getChildCount() > 0) {
                View divider = inflater.inflate(R.layout.afc_view_locations_divider, null);

                if (lpDivider == null) {
                    lpDivider = new LinearLayout.LayoutParams(dim, dim);
                    lpDivider.gravity = Gravity.CENTER;
                    lpDivider.setMargins(dim, dim, dim, dim);
                }
                mViewAddressBar.addView(divider, 0, lpDivider);
            }

            Uri lastUri = Uri.parse(progress[0].getString(progress[0].getColumnIndex(BaseFile.COLUMN_URI)));

            TextView btnLoc = (TextView) inflater.inflate(R.layout.afc_button_location, null);
            String name = BaseFileProviderUtils.getFileName(progress[0]);
            btnLoc.setText(TextUtils.isEmpty(name) ? getString(R.string.afc_root) : name);
            btnLoc.setTag(lastUri);
            btnLoc.setOnClickListener(mBtnLocationOnClickListener);
            btnLoc.setOnLongClickListener(mBtnLocationOnLongClickListener);
            mViewAddressBar.addView(btnLoc, 0, lpBtnLoc);

            if (count++ == 0) {
                Rect r = new Rect();
                btnLoc.getPaint().getTextBounds(name, 0, name.length(), r);
                if (r.width() >= getResources().getDimensionPixelSize(R.dimen.afc_button_location_max_width)
                        - btnLoc.getPaddingLeft() - btnLoc.getPaddingRight()) {
                    mTextFullDirName
                            .setText(progress[0].getString(progress[0].getColumnIndex(BaseFile.COLUMN_NAME)));
                    mTextFullDirName.setVisibility(View.VISIBLE);
                } else
                    mTextFullDirName.setVisibility(View.GONE);
            } // if
        }// onProgressUpdate()

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            /*
             * Sometimes without delay time, it doesn't work...
             */
            mViewLocationsContainer.postDelayed(new Runnable() {

                public void run() {
                    mViewLocationsContainer.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                }// run()
            }, DisplayPrefs.DELAY_TIME_FOR_VERY_SHORT_ANIMATION);
        }// onPostExecute()

    }.execute();
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * As the name means./* ww  w  .j ava 2s  . c  om*/
 */
private void buildAddressBar(final Uri path) {
    if (path == null)
        return;

    mViewAddressBar.removeAllViews();

    new LoadingDialog<Void, Cursor, Void>(getActivity(), false) {

        LinearLayout.LayoutParams lpBtnLoc;
        LinearLayout.LayoutParams lpDivider;
        LayoutInflater inflater = getLayoutInflater(null);
        final int dim = getResources().getDimensionPixelSize(R.dimen.anhuu_f5be488d_5dp);
        int count = 0;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            lpBtnLoc = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            lpBtnLoc.gravity = Gravity.CENTER;
        }// onPreExecute()

        @Override
        protected Void doInBackground(Void... params) {
            Cursor cursor = getActivity().getContentResolver().query(path, null, null, null, null);
            while (cursor != null) {
                if (cursor.moveToFirst()) {
                    publishProgress(cursor);
                    cursor.close();
                } else
                    break;

                /*
                 * Process the parent directory.
                 */
                Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(BaseFile.COLUMN_URI)));
                cursor = getActivity().getContentResolver()
                        .query(BaseFile.genContentUriApi(uri.getAuthority()).buildUpon()
                                .appendPath(BaseFile.CMD_GET_PARENT)
                                .appendQueryParameter(BaseFile.PARAM_SOURCE, uri.getLastPathSegment()).build(),
                                null, null, null, null);
            } // while

            return null;
        }// doInBackground()

        @Override
        protected void onProgressUpdate(Cursor... progress) {
            /*
             * Add divider.
             */
            if (mViewAddressBar.getChildCount() > 0) {
                View divider = inflater.inflate(R.layout.anhuu_f5be488d_view_locations_divider, null);

                if (lpDivider == null) {
                    lpDivider = new LinearLayout.LayoutParams(dim, dim);
                    lpDivider.gravity = Gravity.CENTER;
                    lpDivider.setMargins(dim, dim, dim, dim);
                }
                mViewAddressBar.addView(divider, 0, lpDivider);
            }

            Uri lastUri = Uri.parse(progress[0].getString(progress[0].getColumnIndex(BaseFile.COLUMN_URI)));

            TextView btnLoc = (TextView) inflater.inflate(R.layout.anhuu_f5be488d_button_location, null);
            String name = BaseFileProviderUtils.getFileName(progress[0]);
            btnLoc.setText(TextUtils.isEmpty(name) ? getString(R.string.anhuu_f5be488d_root) : name);
            btnLoc.setTag(lastUri);
            btnLoc.setOnClickListener(mBtnLocationOnClickListener);
            btnLoc.setOnLongClickListener(mBtnLocationOnLongClickListener);
            mViewAddressBar.addView(btnLoc, 0, lpBtnLoc);

            if (count++ == 0) {
                Rect r = new Rect();
                btnLoc.getPaint().getTextBounds(name, 0, name.length(), r);
                if (r.width() >= getResources()
                        .getDimensionPixelSize(R.dimen.anhuu_f5be488d_button_location_max_width)
                        - btnLoc.getPaddingLeft() - btnLoc.getPaddingRight()) {
                    mTextFullDirName
                            .setText(progress[0].getString(progress[0].getColumnIndex(BaseFile.COLUMN_NAME)));
                    mTextFullDirName.setVisibility(View.VISIBLE);
                } else
                    mTextFullDirName.setVisibility(View.GONE);
            } // if
        }// onProgressUpdate()

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            /*
             * Sometimes without delay time, it doesn't work...
             */
            mViewLocationsContainer.postDelayed(new Runnable() {

                public void run() {
                    mViewLocationsContainer.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                }// run()
            }, Display.DELAY_TIME_FOR_VERY_SHORT_ANIMATION);
        }// onPostExecute()

    }.execute();
}

From source file:com.doubleTwist.drawerlib.ADrawerLayout.java

protected void layoutView(View v, int l, int t, int r, int b) {
    LayoutParams params = (LayoutParams) v.getLayoutParams();

    Rect bounds = new Rect();
    Rect boundsWithoutPeek = new Rect();
    int gravity = params.gravity;
    switch (gravity) {
    case Gravity.RIGHT:
        if (DEBUG)
            Log.d(TAG, "gravity: right");
        bounds.left = r - v.getMeasuredWidth() - mPeekSize.right;
        bounds.top = t;//  w w  w. j  ava  2s.  co  m
        bounds.right = r - mPeekSize.right;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(mPeekSize.right, 0);
        mMinScrollX = -bounds.width();
        break;
    case Gravity.TOP:
        if (DEBUG)
            Log.d(TAG, "gravity: top");
        bounds.left = l;
        bounds.top = t + mPeekSize.top;
        bounds.right = v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight() + mPeekSize.top;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, -mPeekSize.top);
        mMaxScrollY = bounds.height();
        break;
    case Gravity.BOTTOM:
        if (DEBUG)
            Log.d(TAG, "gravity: bottom");
        bounds.left = l;
        bounds.top = b - v.getMeasuredHeight() - mPeekSize.bottom;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = b - mPeekSize.bottom;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, mPeekSize.bottom);
        mMinScrollY = -bounds.height();
        break;
    case Gravity.LEFT:
        if (DEBUG)
            Log.d(TAG, "gravity: left");
        bounds.left = l + mPeekSize.left;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth() + mPeekSize.left;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        mMaxScrollX = bounds.width();
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(-mPeekSize.left, 0);
        break;
    default:
        if (DEBUG)
            Log.d(TAG, "gravity: default");
        bounds.left = l;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        break;
    }

    if (DEBUG) {
        Log.d(TAG, " == VIEW LAYOUT == " + v.toString());
        Log.d(TAG, "bounds: " + bounds.left + "," + bounds.top + "," + bounds.right + "," + bounds.bottom);
    }

    if (mLayoutBounds.containsKey(v))
        mLayoutBounds.remove(v);
    mLayoutBounds.put(v, bounds);
    if (mLayoutBoundsWithoutPeek.containsKey(v))
        mLayoutBoundsWithoutPeek.remove(v);
    mLayoutBoundsWithoutPeek.put(v, boundsWithoutPeek);
}

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

public int[] estimateItemSize(int hSpan, int vSpan, boolean springLoaded) {
    int[] size = new int[2];
    if (getChildCount() > 0) {
        // Use the first non-custom page to estimate the child position
        Rect r = estimateItemPosition(mWorkspace, 0, 0, hSpan, vSpan);
        size[0] = r.width();
        size[1] = r.height();/*from  w w  w .j av a 2 s .  c o m*/
        if (springLoaded) {
            size[0] *= mSpringLoadedShrinkFactor;
            size[1] *= mSpringLoadedShrinkFactor;
        }
        return size;
    } else {
        size[0] = Integer.MAX_VALUE;
        size[1] = Integer.MAX_VALUE;
        return size;
    }
}

From source file:me.test.zxing.ViewfinderView.java

@SuppressLint("DrawAllocation")
@Override/*from   w  w  w.j a  v a 2  s .  com*/
public void onDraw(Canvas canvas) {
    if (cameraManager == null) {
        return; // not ready yet, early draw before done configuring
    }
    Rect frame = cameraManager.getFramingRect();
    Rect previewFrame = cameraManager.getFramingRectInPreview();
    if (frame == null || previewFrame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    if (!isFirst) {
        isFirst = true;
        slideTop = frame.top;
    }

    //    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(resultBitmap != null ? resultColor : maskColor);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);

    if (resultBitmap != null) {
        // Draw the opaque result bitmap over the scanning rectangle
        paint.setAlpha(CURRENT_POINT_OPACITY);
        canvas.drawBitmap(resultBitmap, null, frame, paint);
    } else {

        //
        paint.setColor(ContextCompat.getColor(getContext(), android.R.color.holo_green_dark));
        //
        canvas.drawRect(frame.left, frame.top, frame.left + 50, frame.top + 10, paint);
        canvas.drawRect(frame.left, frame.top, frame.left + 10, frame.top + 50, paint);
        //?
        canvas.drawRect(frame.right - 50, frame.top, frame.right, frame.top + 10, paint);
        canvas.drawRect(frame.right - 10, frame.top, frame.right, frame.top + 50, paint);
        //
        canvas.drawRect(frame.left, frame.bottom - 10, frame.left + 50, frame.bottom, paint);
        canvas.drawRect(frame.left, frame.bottom - 50, frame.left + 10, frame.bottom, paint);
        //?
        canvas.drawRect(frame.right - 50, frame.bottom - 10, frame.right, frame.bottom, paint);
        canvas.drawRect(frame.right - 10, frame.bottom - 50, frame.right, frame.bottom, paint);

        //,??SPEEN_DISTANCE
        slideTop += 5;
        if (slideTop >= frame.bottom) {
            slideTop = frame.top;
        }
        canvas.drawRect(frame.left + 5, slideTop - 6 / 2, frame.right - 5, slideTop + 6 / 2, paint);
        float scaleX = frame.width() / (float) previewFrame.width();
        float scaleY = frame.height() / (float) previewFrame.height();

        List<ResultPoint> currentPossible = possibleResultPoints;
        List<ResultPoint> currentLast = lastPossibleResultPoints;
        int frameLeft = frame.left;
        int frameTop = frame.top;
        if (currentPossible.isEmpty()) {
            lastPossibleResultPoints = null;
        } else {
            possibleResultPoints = new ArrayList<>(5);
            lastPossibleResultPoints = currentPossible;
            paint.setAlpha(CURRENT_POINT_OPACITY);
            paint.setColor(resultPointColor);
            synchronized (currentPossible) {
                for (ResultPoint point : currentPossible) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
                            frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint);
                }
            }
        }
        if (currentLast != null) {
            paint.setAlpha(CURRENT_POINT_OPACITY / 2);
            paint.setColor(resultPointColor);
            synchronized (currentLast) {
                float radius = POINT_SIZE / 2.0f;
                for (ResultPoint point : currentLast) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
                            frameTop + (int) (point.getY() * scaleY), radius, paint);
                }
            }
        }

        // Request another update at the animation interval, but only repaint the laser line,
        // not the entire viewfinder mask.
        postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE,
                frame.right + POINT_SIZE, frame.bottom + POINT_SIZE);
    }
}

From source file:com.android.messaging.ui.conversation.ConversationFragment.java

/**
 * {@inheritDoc} from Fragment//  w w  w  . j a v a  2 s  . co m
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.conversation_fragment, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(android.R.id.list);
    final LinearLayoutManager manager = new LinearLayoutManager(getActivity());
    manager.setStackFromEnd(true);
    manager.setReverseLayout(false);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(manager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator() {
        private final List<ViewHolder> mAddAnimations = new ArrayList<ViewHolder>();
        private PopupTransitionAnimation mPopupTransitionAnimation;

        @Override
        public boolean animateAdd(final ViewHolder holder) {
            final ConversationMessageView view = (ConversationMessageView) holder.itemView;
            final ConversationMessageData data = view.getData();
            endAnimation(holder);
            final long timeSinceSend = System.currentTimeMillis() - data.getReceivedTimeStamp();
            if (data.getReceivedTimeStamp() == InsertNewMessageAction.getLastSentMessageTimestamp()
                    && !data.getIsIncoming() && timeSinceSend < MESSAGE_ANIMATION_MAX_WAIT) {
                final ConversationMessageBubbleView messageBubble = (ConversationMessageBubbleView) view
                        .findViewById(R.id.message_content);
                final Rect startRect = UiUtils.getMeasuredBoundsOnScreen(mComposeMessageView);
                final View composeBubbleView = mComposeMessageView.findViewById(R.id.compose_message_text);
                final Rect composeBubbleRect = UiUtils.getMeasuredBoundsOnScreen(composeBubbleView);
                final AttachmentPreview attachmentView = (AttachmentPreview) mComposeMessageView
                        .findViewById(R.id.attachment_draft_view);
                final Rect attachmentRect = UiUtils.getMeasuredBoundsOnScreen(attachmentView);
                if (attachmentView.getVisibility() == View.VISIBLE) {
                    startRect.top = attachmentRect.top;
                } else {
                    startRect.top = composeBubbleRect.top;
                }
                startRect.top -= view.getPaddingTop();
                startRect.bottom = composeBubbleRect.bottom;
                startRect.left += view.getPaddingRight();

                view.setAlpha(0);
                mPopupTransitionAnimation = new PopupTransitionAnimation(startRect, view);
                mPopupTransitionAnimation.setOnStartCallback(new Runnable() {
                    @Override
                    public void run() {
                        final int startWidth = composeBubbleRect.width();
                        attachmentView.onMessageAnimationStart();
                        messageBubble.kickOffMorphAnimation(startWidth,
                                messageBubble.findViewById(R.id.message_text_and_info).getMeasuredWidth());
                    }
                });
                mPopupTransitionAnimation.setOnStopCallback(new Runnable() {
                    @Override
                    public void run() {
                        view.setAlpha(1);
                    }
                });
                mPopupTransitionAnimation.startAfterLayoutComplete();
                mAddAnimations.add(holder);
                return true;
            } else {
                return super.animateAdd(holder);
            }
        }

        @Override
        public void endAnimation(final ViewHolder holder) {
            if (mAddAnimations.remove(holder)) {
                holder.itemView.clearAnimation();
            }
            super.endAnimation(holder);
        }

        @Override
        public void endAnimations() {
            for (final ViewHolder holder : mAddAnimations) {
                holder.itemView.clearAnimation();
            }
            mAddAnimations.clear();
            if (mPopupTransitionAnimation != null) {
                mPopupTransitionAnimation.cancel();
            }
            super.endAnimations();
        }
    });
    mRecyclerView.setAdapter(mAdapter);

    if (savedInstanceState != null) {
        mListState = savedInstanceState.getParcelable(SAVED_INSTANCE_STATE_LIST_VIEW_STATE_KEY);
    }

    mConversationComposeDivider = view.findViewById(R.id.conversation_compose_divider);
    mScrollToDismissThreshold = ViewConfiguration.get(getActivity()).getScaledTouchSlop();
    mRecyclerView.addOnScrollListener(mListScrollListener);
    mFastScroller = ConversationFastScroller.addTo(mRecyclerView,
            UiUtils.isRtlMode() ? ConversationFastScroller.POSITION_LEFT_SIDE
                    : ConversationFastScroller.POSITION_RIGHT_SIDE);

    mComposeMessageView = (ComposeMessageView) view.findViewById(R.id.message_compose_view_container);
    // Bind the compose message view to the DraftMessageData
    mComposeMessageView.bind(DataModel.get().createDraftMessageData(mBinding.getData().getConversationId()),
            this);

    return view;
}

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

private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, DragView dragView, CellLayout layout,
        ItemInfo info, int[] targetCell, boolean external, boolean scale) {
    // Now we animate the dragView, (ie. the widget or shortcut preview) into its final
    // location and size on the home screen.
    int spanX = info.spanX;
    int spanY = info.spanY;

    Rect r = estimateItemPosition(layout, targetCell[0], targetCell[1], spanX, spanY);
    loc[0] = r.left;//from ww w  . jav  a 2  s.  c o m
    loc[1] = r.top;

    setFinalTransitionTransform(layout);
    float cellLayoutScale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true);
    resetTransitionTransform(layout);

    float dragViewScaleX;
    float dragViewScaleY;
    if (scale) {
        dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
        dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();
    } else {
        dragViewScaleX = 1f;
        dragViewScaleY = 1f;
    }

    // The animation will scale the dragView about its center, so we need to center about
    // the final location.
    loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2;
    loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2;

    scaleXY[0] = dragViewScaleX * cellLayoutScale;
    scaleXY[1] = dragViewScaleY * cellLayoutScale;
}

From source file:com.android.launcher3.CellLayout.java

private void markCellsForRect(Rect r, boolean[][] occupied, boolean value) {
    markCellsForView(r.left, r.top, r.width(), r.height(), occupied, value);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

/**
 * Return the layout for a numbered event. Create it if not already existing
 *//*w  w w.j a v  a 2  s  .c  o m*/
private StaticLayout getEventLayout(StaticLayout[] layouts, int i, Event event, Paint paint, Rect r) {
    if (i < 0 || i >= layouts.length) {
        return null;
    }

    StaticLayout layout = layouts[i];
    // Check if we have already initialized the StaticLayout and that
    // the width hasn't changed (due to vertical resizing which causes
    // re-layout of events at min height)
    if (layout == null || r.width() != layout.getWidth()) {
        SpannableStringBuilder bob = new SpannableStringBuilder();
        if (event.title != null) {
            // MAX - 1 since we add a space
            bob.append(drawTextSanitizer(event.title.toString(), MAX_EVENT_TEXT_LEN - 1));
            bob.setSpan(new StyleSpan(Typeface.BOLD), 0, bob.length(), 0);
            bob.append(' ');
        }
        if (event.location != null) {
            bob.append(drawTextSanitizer(event.location.toString(), MAX_EVENT_TEXT_LEN - bob.length()));
        }

        paint.setColor(mEventTextColor);

        // Leave a one pixel boundary on the left and right of the rectangle for the event
        layout = new StaticLayout(bob, 0, bob.length(), new TextPaint(paint), r.width(), Alignment.ALIGN_NORMAL,
                1.0f, 0.0f, true, null, r.width());

        layouts[i] = layout;
    }
    layout.getPaint().setAlpha(mEventsAlpha);
    return layout;
}