Search in sources :

Example 1 with FolderRingAnimator

use of com.android.launcher2.FolderIcon.FolderRingAnimator in project Launcher3 by chislon.

the class CellLayout method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        Drawable bg;
        if (mUseActiveGlowBackground) {
            // In the mini case, we draw the active_glow bg *over* the active background
            bg = mActiveGlowBackground;
        } else {
            bg = mNormalBackground;
        }
        bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
        bg.setBounds(mBackgroundRect);
        bg.draw(canvas);
    }
    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }
    // requires an expanded clip rect (due to the glow's blur radius)
    if (mPressedOrFocusedIcon != null) {
        final int padding = mPressedOrFocusedIcon.getPressedOrFocusedBackgroundPadding();
        final Bitmap b = mPressedOrFocusedIcon.getPressedOrFocusedBackground();
        if (b != null) {
            int offset = getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth);
            int left = getPaddingLeft() + (int) Math.ceil(offset / 2f);
            int top = getPaddingTop();
            canvas.drawBitmap(b, mPressedOrFocusedIcon.getLeft() + left - padding, mPressedOrFocusedIcon.getTop() + top - padding, null);
        }
    }
    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }
    int previewOffset = FolderRingAnimator.sPreviewSize;
    // The folder outer / inner ring image(s)
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderRingAnimator fra = mFolderOuterRings.get(i);
        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset;
            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }
            // Draw inner ring
            d = FolderRingAnimator.sSharedInnerRingDrawable;
            width = (int) (fra.getInnerRingSize() * getChildrenScale());
            height = width;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();
        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) FolderRingAnimator(com.android.launcher3.FolderIcon.FolderRingAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) Paint(android.graphics.Paint) View(android.view.View) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 2 with FolderRingAnimator

use of com.android.launcher2.FolderIcon.FolderRingAnimator in project android_packages_apps_Launcher2 by CyanogenMod.

the class CellLayout method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        Drawable bg;
        if (mIsDragOverlapping) {
            // In the mini case, we draw the active_glow bg *over* the active background
            bg = mActiveGlowBackground;
        } else {
            bg = mNormalBackground;
        }
        bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
        bg.setBounds(mBackgroundRect);
        bg.draw(canvas);
    }
    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            scaleRectAboutCenter(r, temp, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, temp, paint);
        }
    }
    // requires an expanded clip rect (due to the glow's blur radius)
    if (mPressedOrFocusedIcon != null) {
        final int padding = mPressedOrFocusedIcon.getPressedOrFocusedBackgroundPadding();
        final Bitmap b = mPressedOrFocusedIcon.getPressedOrFocusedBackground();
        if (b != null) {
            canvas.drawBitmap(b, mPressedOrFocusedIcon.getLeft() + getPaddingLeft() - padding, mPressedOrFocusedIcon.getTop() + getPaddingTop() - padding, null);
        }
    }
    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }
    int previewOffset = FolderRingAnimator.sPreviewSize;
    // The folder outer / inner ring image(s)
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderRingAnimator fra = mFolderOuterRings.get(i);
        // Draw outer ring
        Drawable d = FolderRingAnimator.sSharedOuterRingDrawable;
        int width = (int) fra.getOuterRingSize();
        int height = width;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        int centerX = mTempLocation[0] + mCellWidth / 2;
        int centerY = mTempLocation[1] + previewOffset / 2;
        canvas.save();
        canvas.translate(centerX - width / 2, centerY - height / 2);
        d.setBounds(0, 0, width, height);
        d.draw(canvas);
        canvas.restore();
        // Draw inner ring
        d = FolderRingAnimator.sSharedInnerRingDrawable;
        width = (int) fra.getInnerRingSize();
        height = width;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        centerX = mTempLocation[0] + mCellWidth / 2;
        centerY = mTempLocation[1] + previewOffset / 2;
        canvas.save();
        canvas.translate(centerX - width / 2, centerY - width / 2);
        d.setBounds(0, 0, width, height);
        d.draw(canvas);
        canvas.restore();
    }
    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();
        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        int centerX = mTempLocation[0] + mCellWidth / 2;
        int centerY = mTempLocation[1] + previewOffset / 2;
        canvas.save();
        canvas.translate(centerX - width / 2, centerY - width / 2);
        d.setBounds(0, 0, width, height);
        d.draw(canvas);
        canvas.restore();
    }
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) FolderRingAnimator(com.android.launcher2.FolderIcon.FolderRingAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Aggregations

Bitmap (android.graphics.Bitmap)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 Rect (android.graphics.Rect)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)2 View (android.view.View)1 FolderRingAnimator (com.android.launcher2.FolderIcon.FolderRingAnimator)1 FolderRingAnimator (com.android.launcher3.FolderIcon.FolderRingAnimator)1