Example usage for android.graphics Canvas setDrawFilter

List of usage examples for android.graphics Canvas setDrawFilter

Introduction

In this page you can find the example usage for android.graphics Canvas setDrawFilter.

Prototype

public void setDrawFilter(@Nullable DrawFilter filter) 

Source Link

Usage

From source file:Main.java

public static Canvas createFilterCanvas(Bitmap bitmap) {
    Canvas canvas = new Canvas(bitmap);
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, 7));
    return canvas;
}

From source file:Main.java

/**
 * Returns a Bitmap representing the thumbnail of the specified Bitmap. The
 * size of the thumbnail is defined by the dimension
 * android.R.dimen.launcher_application_icon_size.
 * <p>//from   www  .ja va  2 s  .  co m
 * This method is not thread-safe and should be invoked on the UI thread
 * only.
 *
 * @param bitmap  The bitmap to get a thumbnail of.
 * @param context The application's context.
 * @return A thumbnail for the specified bitmap or the bitmap itself if the
 * thumbnail could not be created.
 */
public static Bitmap createThumbnailBitmap(Bitmap bitmap, Context context) {
    int sIconWidth = -1;
    int sIconHeight = -1;
    final Resources resources = context.getResources();
    sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);

    final Paint sPaint = new Paint();
    final Rect sBounds = new Rect();
    final Rect sOldBounds = new Rect();
    Canvas sCanvas = new Canvas();

    int width = sIconWidth;
    int height = sIconHeight;

    sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG));

    final int bitmapWidth = bitmap.getWidth();
    final int bitmapHeight = bitmap.getHeight();

    if (width > 0 && height > 0) {
        if (width < bitmapWidth || height < bitmapHeight) {
            final float ratio = (float) bitmapWidth / bitmapHeight;

            if (bitmapWidth > bitmapHeight) {
                height = (int) (width / ratio);
            } else if (bitmapHeight > bitmapWidth) {
                width = (int) (height * ratio);
            }

            final Config c = (width == sIconWidth && height == sIconHeight) ? bitmap.getConfig()
                    : Config.ARGB_8888;
            final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
            final Canvas canvas = sCanvas;
            final Paint paint = sPaint;
            canvas.setBitmap(thumb);
            paint.setDither(false);
            paint.setFilterBitmap(true);
            sBounds.set((sIconWidth - width) / 2, (sIconHeight - height) / 2, width, height);
            sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
            canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
            return thumb;
        } else if (bitmapWidth < width || bitmapHeight < height) {
            final Config c = Config.ARGB_8888;
            final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
            final Canvas canvas = sCanvas;
            final Paint paint = sPaint;
            canvas.setBitmap(thumb);
            paint.setDither(false);
            paint.setFilterBitmap(true);
            canvas.drawBitmap(bitmap, (sIconWidth - bitmapWidth) / 2, (sIconHeight - bitmapHeight) / 2, paint);
            return thumb;
        }
    }

    return bitmap;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float cornerRadius) {
    if (bitmap == null) {
        return null;
    }/*from ww  w.  j a  v a2s.  c o m*/
    Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(result);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);
    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG));
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(result, rect, rect, paint);

    return result;
}

From source file:org.gateshipone.odyssey.playbackservice.managers.OdysseyNotificationManager.java

public void updateNotification(TrackModel track, PlaybackService.PLAYSTATE state,
        MediaSessionCompat.Token mediaSessionToken) {
    if (track != null) {
        mNotificationBuilder = new NotificationCompat.Builder(mContext);

        // Open application intent
        Intent contentIntent = new Intent(mContext, OdysseyMainActivity.class);
        contentIntent.putExtra(OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW,
                OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW_NOWPLAYINGVIEW);
        contentIntent.addFlags(//from www  .j av a2 s .c  om
                Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY);
        PendingIntent contentPendingIntent = PendingIntent.getActivity(mContext, NOTIFICATION_INTENT_OPENGUI,
                contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setContentIntent(contentPendingIntent);

        // Set pendingintents
        // Previous song action
        Intent prevIntent = new Intent(PlaybackService.ACTION_PREVIOUS);
        PendingIntent prevPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PREVIOUS,
                prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_previous_48dp, "Previous", prevPendingIntent).build();

        // Pause/Play action
        PendingIntent playPauseIntent;
        int playPauseIcon;
        if (state == PlaybackService.PLAYSTATE.PLAYING) {
            Intent pauseIntent = new Intent(PlaybackService.ACTION_PAUSE);
            playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, pauseIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_pause_48dp;
        } else {
            Intent playIntent = new Intent(PlaybackService.ACTION_PLAY);
            playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, playIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_play_arrow_48dp;
        }
        NotificationCompat.Action playPauseAction = new NotificationCompat.Action.Builder(playPauseIcon,
                "PlayPause", playPauseIntent).build();

        // Next song action
        Intent nextIntent = new Intent(PlaybackService.ACTION_NEXT);
        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_NEXT,
                nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_next_48dp, "Next", nextPendingIntent).build();

        // Quit action
        Intent quitIntent = new Intent(PlaybackService.ACTION_QUIT);
        PendingIntent quitPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_QUIT,
                quitIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setDeleteIntent(quitPendingIntent);

        mNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        mNotificationBuilder.setSmallIcon(R.drawable.odyssey_notification);
        mNotificationBuilder.addAction(prevAction);
        mNotificationBuilder.addAction(playPauseAction);
        mNotificationBuilder.addAction(nextAction);
        NotificationCompat.MediaStyle notificationStyle = new NotificationCompat.MediaStyle();
        notificationStyle.setShowActionsInCompactView(1, 2);
        notificationStyle.setMediaSession(mediaSessionToken);
        mNotificationBuilder.setStyle(notificationStyle);
        mNotificationBuilder.setContentTitle(track.getTrackName());
        mNotificationBuilder.setContentText(track.getTrackArtistName());

        // Remove unnecessary time info
        mNotificationBuilder.setWhen(0);

        // Cover but only if changed
        if (mLastTrack == null || !track.getTrackAlbumKey().equals(mLastTrack.getTrackAlbumKey())) {
            mLastTrack = track;
            mLastBitmap = null;
        }

        // Only set image if an saved one is available
        if (mLastBitmap != null) {
            mNotificationBuilder.setLargeIcon(mLastBitmap);
        } else {
            /**
             * Create a dummy placeholder image for versions greater android 7 because it
             * does not automatically show the application icon anymore in mediastyle notifications.
             */
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Drawable icon = mContext.getDrawable(R.drawable.notification_placeholder_256dp);

                Bitmap iconBitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(iconBitmap);
                DrawFilter filter = new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, 1);

                canvas.setDrawFilter(filter);
                icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                icon.setFilterBitmap(true);

                icon.draw(canvas);
                mNotificationBuilder.setLargeIcon(iconBitmap);

            } else {
                /**
                 * For older android versions set the null icon which will result in a dummy icon
                 * generated from the application icon.
                 */
                mNotificationBuilder.setLargeIcon(null);

            }
        }

        // Build the notification
        mNotification = mNotificationBuilder.build();

        // Check if run from service and check if playing or pause.
        // Pause notification should be dismissible.
        if (mContext instanceof Service) {
            if (state == PlaybackService.PLAYSTATE.PLAYING) {
                ((Service) mContext).startForeground(NOTIFICATION_ID, mNotification);
            } else {
                ((Service) mContext).stopForeground(false);
            }
        }

        // Send the notification away
        mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    }

}

From source file:com.visenze.visearch.camerademo.views.RoundImageView.java

@Override
protected void onDraw(Canvas canvas) {

    if (mBounds == null) {
        return;//w w  w .jav a 2  s  .  c o  m
    }

    int width = mBounds.width();
    int height = mBounds.height();

    if (width == 0 || height == 0) {
        return;
    }

    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));

    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {

        // Need to redraw the cache
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }

        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        cacheCanvas
                .setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint,
                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }

        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }

    // Draw from cache
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}

From source file:org.gateshipone.malp.application.background.NotificationManager.java

public synchronized void updateNotification(MPDTrack track, MPDCurrentStatus.MPD_PLAYBACK_STATE state) {
    if (track != null) {
        mNotificationBuilder = new NotificationCompat.Builder(mService);

        // Open application intent
        Intent contentIntent = new Intent(mService, MainActivity.class);
        contentIntent.putExtra(MainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW,
                MainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW_NOWPLAYINGVIEW);
        contentIntent.addFlags(//w  w  w  .  j  ava 2 s . com
                Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY);
        PendingIntent contentPendingIntent = PendingIntent.getActivity(mService, INTENT_OPENGUI, contentIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setContentIntent(contentPendingIntent);

        // Set pendingintents
        // Previous song action
        Intent prevIntent = new Intent(BackgroundService.ACTION_PREVIOUS);
        PendingIntent prevPendingIntent = PendingIntent.getBroadcast(mService, INTENT_PREVIOUS, prevIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_previous_48dp, "Previous", prevPendingIntent).build();

        // Pause/Play action
        PendingIntent playPauseIntent;
        int playPauseIcon;
        if (state == MPDCurrentStatus.MPD_PLAYBACK_STATE.MPD_PLAYING) {
            Intent pauseIntent = new Intent(BackgroundService.ACTION_PAUSE);
            playPauseIntent = PendingIntent.getBroadcast(mService, INTENT_PLAYPAUSE, pauseIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_pause_48dp;
        } else {
            Intent playIntent = new Intent(BackgroundService.ACTION_PLAY);
            playPauseIntent = PendingIntent.getBroadcast(mService, INTENT_PLAYPAUSE, playIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_play_arrow_48dp;
        }
        NotificationCompat.Action playPauseAction = new NotificationCompat.Action.Builder(playPauseIcon,
                "PlayPause", playPauseIntent).build();

        // Stop action
        Intent stopIntent = new Intent(BackgroundService.ACTION_STOP);
        PendingIntent stopPendingIntent = PendingIntent.getBroadcast(mService, INTENT_STOP, stopIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action stopActon = new NotificationCompat.Action.Builder(
                R.drawable.ic_stop_black_48dp, "Stop", stopPendingIntent).build();

        // Next song action
        Intent nextIntent = new Intent(BackgroundService.ACTION_NEXT);
        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mService, INTENT_NEXT, nextIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_next_48dp, "Next", nextPendingIntent).build();

        // Quit action
        Intent quitIntent = new Intent(BackgroundService.ACTION_QUIT_BACKGROUND_SERVICE);
        PendingIntent quitPendingIntent = PendingIntent.getBroadcast(mService, INTENT_QUIT, quitIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setDeleteIntent(quitPendingIntent);

        mNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        mNotificationBuilder.setSmallIcon(R.drawable.ic_notification_24dp);
        mNotificationBuilder.addAction(prevAction);
        mNotificationBuilder.addAction(playPauseAction);
        mNotificationBuilder.addAction(stopActon);
        mNotificationBuilder.addAction(nextAction);
        NotificationCompat.MediaStyle notificationStyle = new NotificationCompat.MediaStyle();
        notificationStyle.setShowActionsInCompactView(1, 2);
        mNotificationBuilder.setStyle(notificationStyle);

        String title;
        if (track.getTrackTitle().isEmpty()) {
            title = FormatHelper.getFilenameFromPath(track.getPath());
        } else {
            title = track.getTrackTitle();
        }

        mNotificationBuilder.setContentTitle(title);

        String secondRow;

        if (!track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) {
            secondRow = track.getTrackArtist() + mService.getString(R.string.track_item_separator)
                    + track.getTrackAlbum();
        } else if (track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) {
            secondRow = track.getTrackAlbum();
        } else if (track.getTrackAlbum().isEmpty() && !track.getTrackArtist().isEmpty()) {
            secondRow = track.getTrackArtist();
        } else {
            secondRow = track.getPath();
        }

        // Set the media session metadata
        updateMetadata(track, state);

        mNotificationBuilder.setContentText(secondRow);

        // Remove unnecessary time info
        mNotificationBuilder.setWhen(0);

        // Cover but only if changed
        if (mNotification == null || !track.getTrackAlbum().equals(mLastTrack.getTrackAlbum())) {
            mLastTrack = track;
            mLastBitmap = null;
            mCoverLoader.getImage(mLastTrack, true);
        }

        // Only set image if an saved one is available
        if (mLastBitmap != null) {
            mNotificationBuilder.setLargeIcon(mLastBitmap);
        } else {
            /**
             * Create a dummy placeholder image for versions greater android 7 because it
             * does not automatically show the application icon anymore in mediastyle notifications.
             */
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Drawable icon = mService.getDrawable(R.drawable.notification_placeholder_256dp);

                Bitmap iconBitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(iconBitmap);
                DrawFilter filter = new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, 1);

                canvas.setDrawFilter(filter);
                icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                icon.setFilterBitmap(true);

                icon.draw(canvas);
                mNotificationBuilder.setLargeIcon(iconBitmap);
            } else {
                /**
                 * For older android versions set the null icon which will result in a dummy icon
                 * generated from the application icon.
                 */
                mNotificationBuilder.setLargeIcon(null);
            }
        }

        // Build the notification
        mNotification = mNotificationBuilder.build();

        // Send the notification away
        mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    }
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

@Override
protected void onDraw(Canvas canvas) {

    if (mAdapter == null) {
        super.onDraw(canvas);
        return;//  w ww.j  ava  2 s .  c o m
    }

    canvas.setDrawFilter(mDrawFilter);

    final float offset = mOffset;
    int i = 0;
    int mid = (int) Math.floor(offset + 0.5);

    int rightChild = (mVisibleChildCount % 2 == 0) ? (mVisibleChildCount >> 1) - 1 : mVisibleChildCount >> 1;
    int leftChild = mVisibleChildCount >> 1;

    // draw the left children
    int startPos = mid - leftChild;
    for (i = startPos; i < mid; ++i) {
        drawChild(canvas, mid, i, i - offset);
    }

    // draw the right children
    int endPos = mid + rightChild;
    for (i = endPos; i >= mid; --i) {
        drawChild(canvas, mid, i, i - offset);
    }

    if ((offset - (int) offset) == 0.0f) {
        imageOnTop(getActuallyPosition((int) offset));
    }

    super.onDraw(canvas);

    mCoverFlowListener.invalidationCompleted();
}

From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java

@Override
protected void onDraw(Canvas canvas) {

    if (mAdapter == null) {
        super.onDraw(canvas);
        return;//  w w w  .  j  a  v a 2s .  co  m
    }

    mDrawing = true;

    canvas.setDrawFilter(mDrawFilter);

    final float offset = mOffset;
    int i = 0;
    int mid = (int) Math.floor(offset + 0.5);

    int rightChild = (mVisibleChildCount % 2 == 0) ? (mVisibleChildCount >> 1) - 1 : mVisibleChildCount >> 1;
    int leftChild = mVisibleChildCount >> 1;

    // draw the left children
    int startPos = mid - leftChild;
    for (i = startPos; i < mid; ++i) {
        drawChild(canvas, i, i - offset);
    }

    // draw the right children
    int endPos = mid + rightChild;
    for (i = endPos; i >= mid; --i) {
        drawChild(canvas, i, i - offset);
    }

    if (mLastOffset != (int) offset) {
        imageOnTop(getActuallyPosition((int) offset));
        mLastOffset = (int) offset;
    }

    mDrawing = false;
    final int removeCount = mRemoveReflectionPendingArray.size();
    for (i = 0; i < removeCount; i++) {
        final int removePosition = mRemoveReflectionPendingArray.get(i);
        mRecycler.removeCachedBitmap(removePosition);
    }
    mRemoveReflectionPendingArray.clear();

    super.onDraw(canvas);

    if (mCoverFlowListener != null) {
        mCoverFlowListener.invalidationCompleted();
    }
}

From source file:com.atobo.safecoo.view.coverflow.CoverFlowView.java

@Override
protected void onDraw(Canvas canvas) {

    if (mAdapter == null) {
        super.onDraw(canvas);
        return;//from   w  w w  .  j a va2  s .  c  o m
    }

    mDrawing = true;

    canvas.setDrawFilter(mDrawFilter);

    final float offset = mOffset;
    int i = 0;
    int mid = (int) Math.floor(offset + 0.5);

    int rightChild = (mVisibleChildCount % 2 == 0) ? (mVisibleChildCount >> 1) - 1 : mVisibleChildCount >> 1;
    int leftChild = mVisibleChildCount >> 1;

    // draw the left children
    int startPos = mid - leftChild;
    for (i = startPos; i < mid; ++i) {
        drawChild(canvas, i, i - offset);
    }

    // draw the right children
    int endPos = mid + rightChild;
    for (i = endPos; i >= mid; --i) {
        drawChild(canvas, i, i - offset);
    }

    if (mLastOffset != (int) offset) {
        imageOnTop(getActuallyPosition((int) offset));
        mLastOffset = (int) offset;
    }

    mDrawing = false;
    final int removeCount = mRemoveReflectionPendingArray.size();
    for (i = 0; i < removeCount; i++) {
        final int removePosition = mRemoveReflectionPendingArray.get(i);
        mRecycler.removeCachedBitmap(removePosition);
    }
    mRemoveReflectionPendingArray.clear();

    super.onDraw(canvas);
    if (mCoverFlowListener != null) {
        mCoverFlowListener.invalidationCompleted();
    }
}

From source file:com.dolphinwang.imagecoverflow.CoverFlowView.java

@Override
protected void onDraw(Canvas canvas) {

    if (mAdapter == null) {
        super.onDraw(canvas);
        return;// w w  w  .  j ava2  s .c om
    }

    mDrawing = true;

    canvas.setDrawFilter(mDrawFilter);

    final float offset = mOffset;
    int i = 0;
    int mid = (int) Math.floor(offset + 0.5);

    int rightChild = (mVisibleChildCount % 2 == 0) ? (mVisibleChildCount >> 1) - 1 : mVisibleChildCount >> 1;
    int leftChild = mVisibleChildCount >> 1;

    // draw the left children
    int startPos = mid - leftChild;
    for (i = startPos; i < mid; ++i) {
        drawChild(canvas, i, i - offset);
    }

    // draw the right children
    int endPos = mid + rightChild;
    for (i = endPos; i >= mid; --i) {
        drawChild(canvas, i, i - offset);
    }

    if (mLastOffset != (int) offset) {
        imageOnTop(getActuallyPosition((int) offset));
        mLastOffset = (int) offset;
    }

    mDrawing = false;
    final int removeCount = mRemoveReflectionPendingArray.size();
    for (i = 0; i < removeCount; i++) {
        final int removePosition = mRemoveReflectionPendingArray.get(i);
        mRecycler.removeCachedBitmap(removePosition);
    }
    mRemoveReflectionPendingArray.clear();

    super.onDraw(canvas);

    mCoverFlowListener.invalidationCompleted();
}