content: /*
   * Copyright (C) 2015 AChep@xda <artemchep@gmail.com>
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   * MA  02110-1301, USA.
   */
  package com.achep.base.ui.drawables;
  
  import android.graphics.Canvas;
  import android.graphics.ColorFilter;
  import android.graphics.Paint;
  import android.graphics.PixelFormat;
  import android.graphics.Rect;
  import android.graphics.drawable.Drawable;
  
  /**
   * Created by Artem Chepurnoy on 15.02.2015.
   */
  public class CircleDrawable extends Drawable {
  
      private final Paint mPaint;
  
      public CircleDrawable() {
          mPaint = new Paint();
          mPaint.setAntiAlias(true);
          mPaint.setStyle(Paint.Style.FILL);
      }
  
      public void setColor(int color) {
          mPaint.setColor(color | 0xFF000000); // ignore alpha bits
          invalidateSelf();
      }
  
      /**
       * {@inheritDoc}
       */
      @Override
      public void draw(Canvas canvas) {
          final Rect rect = getBounds();
          canvas.drawCircle(
                  rect.exactCenterX(),
                  rect.exactCenterY(),
                  Math.min(rect.height(), rect.width()) / 2f, mPaint);
      }
  
      /**
       * {@inheritDoc}
       */
      @Override
      public void setAlpha(int alpha) {
          mPaint.setAlpha(alpha);
          invalidateSelf();
      }
  
      /**
       * {@inheritDoc}
       */
      @Override
      public void setColorFilter(ColorFilter cf) {
          mPaint.setColorFilter(cf);
          invalidateSelf();
      }
  
      /**
       * {@inheritDoc}
       */
      @Override
      public int getOpacity() {
          return PixelFormat.TRANSLUCENT;
      }
  }
  