Android Open Source - Aviary-Android-SDK Glow Bitmap Drawable






From Project

Back to project page Aviary-Android-SDK.

License

The source code is released under:

AVIARY API TERMS OF USE Full Legal Agreement The following terms and conditions and the terms and conditions at http://www.aviary.com/terms (collectively, the ?Terms??) govern your use of any and ...

If you think the Android project Aviary-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.aviary.android.feather.graphics;
//from   w  w  w  .  j  a va  2s.co m
import it.sephiroth.android.library.imagezoom.graphics.FastBitmapDrawable;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;

import com.aviary.android.feather.utils.UIUtils;

public class GlowBitmapDrawable extends FastBitmapDrawable {

  @SuppressWarnings ( "unused" )
  private static final String LOG_TAG = "glow-drawable";

  private Rect mDstRect = new Rect();

  private Bitmap mPressedBitmap;
  private Bitmap mCheckedBitmap;
  private Bitmap mSelectedBitmap;

  private Bitmap mCurrent;

  private boolean mPressed;
  private boolean mChecked;
  private boolean mSelected;

  private int mHighlightColorPressed;
  private int mHighlightColorChecked;
  private int mHighlightColorSelected;

  private int mBlurValue;
  private int mGlowMode, mHighlightMode;

  public GlowBitmapDrawable ( Resources res, Bitmap bitmap, int color_pressed, int color_checked, int color_selected, int blur_size, int highlightMode,
      int glowMode ) {
    super( bitmap );
    init( color_pressed, color_checked, color_selected, blur_size, highlightMode, glowMode );
  }

  private void init( int color_pressed, int color_checked, int color_selected, int blur_size, int highlightMode, int glowMode ) {
    mHighlightColorChecked = color_checked;
    mHighlightColorPressed = color_pressed;
    mHighlightColorSelected = color_selected;
    mBlurValue = blur_size;
    mGlowMode = glowMode;
    mHighlightMode = highlightMode;

    mCurrent = getBitmap();
    recycleBitmaps();
  }

  public void setBitmap( Bitmap bitmap ) {
    super.setBitmap( bitmap );
    mCurrent = bitmap;
    recycleBitmaps();
  }

  private void recycleBitmaps() {
    if ( null != mCheckedBitmap ) {
      mCheckedBitmap.recycle();
      mCheckedBitmap = null;
    }

    if ( null != mPressedBitmap ) {
      mPressedBitmap.recycle();
      mPressedBitmap = null;
    }

    if ( null != mSelectedBitmap ) {
      mSelectedBitmap.recycle();
      mSelectedBitmap = null;
    }
  }

  public void updateConfig( int color_pressed, int color_checked, int color_selected, int blur_size, int highlightMode, int glowMode ) {
    init( color_pressed, color_checked, color_selected, blur_size, highlightMode, glowMode );
    setState( getState() );
  }

  public static Bitmap generateBlurBitmap( Bitmap src, int blurValue, int color, Mode mode, boolean glow, Paint paint ) {

    int width = src.getWidth();
    int height = src.getHeight();

    Bitmap dest = Bitmap.createBitmap( width, height, src.getConfig() );

    Canvas canvas = new Canvas( dest );
    Bitmap alpha = src.extractAlpha();
    canvas.drawBitmap( src, 0, 0, paint );

    Paint paintBlur = new Paint();
    paintBlur.setXfermode( new PorterDuffXfermode( mode ) );
    paintBlur.setColor( color );
    canvas.drawBitmap( alpha, 0, 0, paintBlur );

    if ( glow ) {
      BlurMaskFilter maskFilter = new BlurMaskFilter( blurValue, BlurMaskFilter.Blur.NORMAL );
      paintBlur.setMaskFilter( maskFilter );
      paintBlur.setAlpha( 100 );
      canvas.drawBitmap( alpha, 0, 0, paintBlur );
    }

    return dest;
  }

  @Override
  public boolean isStateful() {
    return true;
  }

  @Override
  public void draw( Canvas canvas ) {
    copyBounds( mDstRect );
    canvas.drawBitmap( mCurrent, null, mDstRect, getPaint() );
  }

  @Override
  protected boolean onStateChange( int[] state ) {

    boolean checked = mChecked;
    boolean pressed = mPressed;
    boolean selected = mSelected;

    mChecked = false;
    mPressed = false;
    mSelected = false;

    for ( int i = 0; i < state.length; i++ ) {
      if ( state[i] == android.R.attr.state_pressed ) {
        mPressed = true;
        continue;
      }

      if ( state[i] == android.R.attr.state_checked ) {
        mChecked = true;
        continue;
      }

      if ( state[i] == android.R.attr.state_selected ) {
        mSelected = true;
        continue;
      }
    }

    if ( mPressed && UIUtils.checkBits( mHighlightMode, UIUtils.HIGHLIGHT_MODE_PRESSED ) ) {
      if ( mPressedBitmap == null ) {
        mPressedBitmap = generateBlurBitmap( getBitmap(), mBlurValue, mHighlightColorPressed, Mode.DARKEN,
            UIUtils.checkBits( mGlowMode, UIUtils.GLOW_MODE_PRESSED ), getPaint() );
      }
      mCurrent = mPressedBitmap;

    } else if ( mChecked && UIUtils.checkBits( mHighlightMode, UIUtils.HIGHLIGHT_MODE_CHECKED ) ) {
      if ( mCheckedBitmap == null ) {
        mCheckedBitmap = generateBlurBitmap( getBitmap(), mBlurValue, mHighlightColorChecked, Mode.DARKEN,
            UIUtils.checkBits( mGlowMode, UIUtils.GLOW_MODE_CHECKED ), getPaint() );
      }
      mCurrent = mCheckedBitmap;

    } else if ( mSelected && UIUtils.checkBits( mHighlightMode, UIUtils.HIGHLIGHT_MODE_SELECTED ) ) {
      if ( mSelectedBitmap == null ) {
        mSelectedBitmap = generateBlurBitmap( getBitmap(), mBlurValue, mHighlightColorSelected, Mode.DARKEN,
            UIUtils.checkBits( mGlowMode, UIUtils.GLOW_MODE_SELECTED ), getPaint() );
      }
      mCurrent = mSelectedBitmap;

    } else {
      mCurrent = getBitmap();
    }

    return checked != mChecked || pressed != mPressed || selected != mSelected;

  }

}




Java Source Code List

com.aviary.android.feather.AlertActivity.java
com.aviary.android.feather.AviaryMainController.java
com.aviary.android.feather.FeatherActivity.java
com.aviary.android.feather.async_tasks.AsyncImageManager.java
com.aviary.android.feather.async_tasks.DownloadImageAsyncTask.java
com.aviary.android.feather.async_tasks.ExifTask.java
com.aviary.android.feather.effects.AbstractContentPanel.java
com.aviary.android.feather.effects.AbstractOptionPanel.java
com.aviary.android.feather.effects.AbstractPanelLoaderService.java
com.aviary.android.feather.effects.AbstractPanel.java
com.aviary.android.feather.effects.AdjustEffectPanel.java
com.aviary.android.feather.effects.BordersPanel.java
com.aviary.android.feather.effects.ColorSplashPanel.java
com.aviary.android.feather.effects.CropPanel.java
com.aviary.android.feather.effects.DelayedSpotDrawPanel.java
com.aviary.android.feather.effects.DrawingPanel.java
com.aviary.android.feather.effects.EffectsPanel.java
com.aviary.android.feather.effects.EnhanceEffectPanel.java
com.aviary.android.feather.effects.MemePanel.java
com.aviary.android.feather.effects.NativeEffectRangePanel.java
com.aviary.android.feather.effects.SimpleStatusMachine.java
com.aviary.android.feather.effects.SliderEffectPanel.java
com.aviary.android.feather.effects.StickersPanel.java
com.aviary.android.feather.effects.TextPanel.java
com.aviary.android.feather.effects.TiltShiftPanel.java
com.aviary.android.feather.graphics.CdsPreviewTransformer.java
com.aviary.android.feather.graphics.GalleryBottomIndicatorDrawable.java
com.aviary.android.feather.graphics.GalleryTopIndicatorDrawable.java
com.aviary.android.feather.graphics.GlowBitmapDrawable.java
com.aviary.android.feather.graphics.GlowDrawable.java
com.aviary.android.feather.graphics.PluginDividerDrawable.java
com.aviary.android.feather.graphics.PreviewFillColorDrawable.java
com.aviary.android.feather.graphics.PreviewSpotDrawable.java
com.aviary.android.feather.graphics.RepeatableHorizontalDrawable.java
com.aviary.android.feather.opengl.AviaryGLSurfaceView.java
com.aviary.android.feather.utils.PackIconCallable.java
com.aviary.android.feather.utils.SimpleBitmapCache.java
com.aviary.android.feather.utils.ThreadUtils.java
com.aviary.android.feather.utils.TypefaceUtils.java
com.aviary.android.feather.utils.UIUtils.java
com.aviary.android.feather.widget.AdjustImageView.java
com.aviary.android.feather.widget.AviaryAbsSpinner.java
com.aviary.android.feather.widget.AviaryAdapterView.java
com.aviary.android.feather.widget.AviaryBadgeToolLayout.java
com.aviary.android.feather.widget.AviaryBottomBarViewFlipper.java
com.aviary.android.feather.widget.AviaryButton.java
com.aviary.android.feather.widget.AviaryEdgeEffect.java
com.aviary.android.feather.widget.AviaryGalleryTopIndicatorView.java
com.aviary.android.feather.widget.AviaryGallery.java
com.aviary.android.feather.widget.AviaryHighlightImageButton.java
com.aviary.android.feather.widget.AviaryImageRestoreSwitcher.java
com.aviary.android.feather.widget.AviaryImageSwitcher.java
com.aviary.android.feather.widget.AviaryNavBarViewFlipper.java
com.aviary.android.feather.widget.AviarySeekBar.java
com.aviary.android.feather.widget.AviaryTextView.java
com.aviary.android.feather.widget.AviaryToast.java
com.aviary.android.feather.widget.AviaryToggleButton.java
com.aviary.android.feather.widget.AviaryWheel.java
com.aviary.android.feather.widget.AviaryWorkspaceIndicator.java
com.aviary.android.feather.widget.AviaryWorkspace.java
com.aviary.android.feather.widget.CellLayout.java
com.aviary.android.feather.widget.CropImageView.java
com.aviary.android.feather.widget.DrawableHighlightView.java
com.aviary.android.feather.widget.EffectThumbLayout.java
com.aviary.android.feather.widget.HighlightView.java
com.aviary.android.feather.widget.IAPBuyButton.java
com.aviary.android.feather.widget.IAPDialogDetail.java
com.aviary.android.feather.widget.IAPDialogList.java
com.aviary.android.feather.widget.IAPDialogMain.java
com.aviary.android.feather.widget.ImageViewDrawableOverlay.java
com.aviary.android.feather.widget.ImageViewSpotDraw.java
com.aviary.android.feather.widget.ImageViewTiltiShiftTouch.java
com.aviary.android.feather.widget.ImageViewTouchAndDraw.java
com.aviary.android.feather.widget.PointCloud.java
com.aviary.android.feather.widget.ScrollerRunnable.java
com.aviary.android.feather.widget.VibrationHelper.java
com.aviary.android.feather.widget.VibrationWidget.java