Example usage for android.graphics Paint ANTI_ALIAS_FLAG

List of usage examples for android.graphics Paint ANTI_ALIAS_FLAG

Introduction

In this page you can find the example usage for android.graphics Paint ANTI_ALIAS_FLAG.

Prototype

int ANTI_ALIAS_FLAG

To view the source code for android.graphics Paint ANTI_ALIAS_FLAG.

Click Source Link

Document

Paint flag that enables antialiasing when drawing.

Usage

From source file:eu.trentorise.smartcampus.trentinofamiglia.map.MapManager.java

private static Bitmap writeOnMarker(Context mContext, int drawableId, String text) {
    float scale = mContext.getResources().getDisplayMetrics().density;

    Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId)
            .copy(Bitmap.Config.ARGB_8888, true);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextAlign(Align.CENTER);/*from ww  w .j  a  v a  2  s .co  m*/
    paint.setTextSize(scale * 14);
    paint.setAntiAlias(true);
    paint.setARGB(255, 255, 255, 255);

    Canvas canvas = new Canvas(bitmap);
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    float x = bitmap.getWidth() / 2;
    float y = bitmap.getHeight() / 2 - 5;
    canvas.drawText(text, x, y, paint);

    return bitmap;
}

From source file:org.akop.ararat.view.CrosswordView.java

public CrosswordView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (!isInEditMode()) {
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }//from  w  w  w .  j ava  2 s. c  o  m

    // Set drawing defaults
    Resources r = context.getResources();
    DisplayMetrics dm = r.getDisplayMetrics();

    int cellFillColor = NORMAL_CELL_FILL_COLOR;
    int cheatedCellFillColor = CHEATED_CELL_FILL_COLOR;
    int mistakeCellFillColor = MISTAKE_CELL_FILL_COLOR;
    int selectedWordFillColor = SELECTED_WORD_FILL_COLOR;
    int selectedCellFillColor = SELECTED_CELL_FILL_COLOR;
    int markedCellFillColor = MARKED_CELL_FILL_COLOR;
    int numberTextColor = NUMBER_TEXT_COLOR;
    int cellStrokeColor = CELL_STROKE_COLOR;
    int circleStrokeColor = CIRCLE_STROKE_COLOR;
    int answerTextColor = ANSWER_TEXT_COLOR;

    mScaledDensity = dm.scaledDensity;
    float numberTextSize = NUMBER_TEXT_SIZE * mScaledDensity;
    mAnswerTextSize = ANSWER_TEXT_SIZE * mScaledDensity;

    mCellSize = CELL_SIZE * dm.density;
    mNumberTextPadding = NUMBER_TEXT_PADDING * dm.density;
    mIsEditable = true;
    mInputMode = INPUT_MODE_KEYBOARD;
    mSkipOccupiedOnType = false;
    mSelectFirstUnoccupiedOnNav = true;
    mMaxBitmapSize = DEFAULT_MAX_BITMAP_DIMENSION;

    // Read supplied attributes
    if (attrs != null) {
        Resources.Theme theme = context.getTheme();
        TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.CrosswordView, 0, 0);

        mCellSize = a.getDimension(R.styleable.CrosswordView_cellSize, mCellSize);
        mNumberTextPadding = a.getDimension(R.styleable.CrosswordView_numberTextPadding, mNumberTextPadding);
        numberTextSize = a.getDimension(R.styleable.CrosswordView_numberTextSize, numberTextSize);
        mAnswerTextSize = a.getDimension(R.styleable.CrosswordView_answerTextSize, mAnswerTextSize);
        answerTextColor = a.getColor(R.styleable.CrosswordView_answerTextColor, answerTextColor);
        cellFillColor = a.getColor(R.styleable.CrosswordView_defaultCellFillColor, cellFillColor);
        cheatedCellFillColor = a.getColor(R.styleable.CrosswordView_cheatedCellFillColor, cheatedCellFillColor);
        mistakeCellFillColor = a.getColor(R.styleable.CrosswordView_mistakeCellFillColor, mistakeCellFillColor);
        selectedWordFillColor = a.getColor(R.styleable.CrosswordView_selectedWordFillColor,
                selectedWordFillColor);
        selectedCellFillColor = a.getColor(R.styleable.CrosswordView_selectedCellFillColor,
                selectedCellFillColor);
        markedCellFillColor = a.getColor(R.styleable.CrosswordView_markedCellFillColor, markedCellFillColor);
        cellStrokeColor = a.getColor(R.styleable.CrosswordView_cellStrokeColor, cellStrokeColor);
        circleStrokeColor = a.getColor(R.styleable.CrosswordView_circleStrokeColor, circleStrokeColor);
        numberTextColor = a.getColor(R.styleable.CrosswordView_numberTextColor, numberTextColor);
        mIsEditable = a.getBoolean(R.styleable.CrosswordView_editable, mIsEditable);
        mSkipOccupiedOnType = a.getBoolean(R.styleable.CrosswordView_skipOccupiedOnType, mSkipOccupiedOnType);
        mSelectFirstUnoccupiedOnNav = a.getBoolean(R.styleable.CrosswordView_selectFirstUnoccupiedOnNav,
                mSelectFirstUnoccupiedOnNav);

        a.recycle();
    }

    mRevealSetsCheatFlag = true;
    mMarkerSideLength = mCellSize * MARKER_TRIANGLE_LENGTH_FRACTION;

    // Init paints
    mCellFillPaint = new Paint();
    mCellFillPaint.setColor(cellFillColor);
    mCellFillPaint.setStyle(Paint.Style.FILL);

    mCheatedCellFillPaint = new Paint();
    mCheatedCellFillPaint.setColor(cheatedCellFillColor);
    mCheatedCellFillPaint.setStyle(Paint.Style.FILL);

    mMistakeCellFillPaint = new Paint();
    mMistakeCellFillPaint.setColor(mistakeCellFillColor);
    mMistakeCellFillPaint.setStyle(Paint.Style.FILL);

    mSelectedWordFillPaint = new Paint();
    mSelectedWordFillPaint.setColor(selectedWordFillColor);
    mSelectedWordFillPaint.setStyle(Paint.Style.FILL);

    mSelectedCellFillPaint = new Paint();
    mSelectedCellFillPaint.setColor(selectedCellFillColor);
    mSelectedCellFillPaint.setStyle(Paint.Style.FILL);

    mMarkedCellFillPaint = new Paint();
    mMarkedCellFillPaint.setColor(markedCellFillColor);
    mMarkedCellFillPaint.setStyle(Paint.Style.FILL);

    mCellStrokePaint = new Paint();
    mCellStrokePaint.setColor(cellStrokeColor);
    mCellStrokePaint.setStyle(Paint.Style.STROKE);
    //      mCellStrokePaint.setStrokeWidth(1);

    mCircleStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCircleStrokePaint.setColor(circleStrokeColor);
    mCircleStrokePaint.setStyle(Paint.Style.STROKE);
    mCircleStrokePaint.setStrokeWidth(1);

    mNumberTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mNumberTextPaint.setColor(numberTextColor);
    mNumberTextPaint.setTextAlign(Paint.Align.CENTER);
    mNumberTextPaint.setTextSize(numberTextSize);

    // Compute number height
    mNumberTextPaint.getTextBounds("0", 0, "0".length(), mTempRect);
    mNumberTextHeight = mTempRect.height();

    mNumberStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mNumberStrokePaint.setColor(cellFillColor);
    mNumberStrokePaint.setTextAlign(Paint.Align.CENTER);
    mNumberStrokePaint.setTextSize(numberTextSize);
    mNumberStrokePaint.setStyle(Paint.Style.STROKE);
    mNumberStrokePaint.setStrokeWidth(NUMBER_TEXT_STROKE_WIDTH * mScaledDensity);

    mAnswerTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mAnswerTextPaint.setColor(answerTextColor);
    mAnswerTextPaint.setTextSize(mAnswerTextSize);

    // Init rest of the values
    mCircleRadius = (mCellSize / 2) - mCircleStrokePaint.getStrokeWidth();
    mPuzzleCells = EMPTY_CELLS;
    mPuzzleWidth = 0;
    mPuzzleHeight = 0;
    mAllowedChars = EMPTY_CHARS;

    mRenderScale = 0;
    mBitmapOffset = new PointF();
    mCenteredOffset = new PointF();
    mTranslationBounds = new RectF();

    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());

    mContentRect = new RectF();
    mPuzzleRect = new RectF();

    mBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG);

    mScroller = new Scroller(context, null, true);
    mZoomer = new Zoomer(context);
    mUndoBuffer = new Stack<>();

    setFocusableInTouchMode(mIsEditable && mInputMode != INPUT_MODE_NONE);
    setOnKeyListener(this);
}

From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java

public static void LoadMenuImage(final String url, MenuItem menuItem, String displayname, final boolean rounded,
        Resources resources, boolean fromCache) {
    final Resources mResources = resources;
    final WeakReference<MenuItem> menuItemImage = new WeakReference<MenuItem>(menuItem);
    final Handler uiHandler = new Handler();
    final int FG_COLOR = 0xFFFAFAFA;
    final String name = displayname;

    if (fromCache) {
        Bitmap bitmap = ThumbnailsCacheManager.getBitmapFromDiskCache(url);

        if (bitmap != null) {
            if (rounded) {
                RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory.create(mResources, bitmap);
                roundedBitmap.setCircular(true);
                menuItemImage.get().setIcon(roundedBitmap);
            } else {
                menuItemImage.get().setIcon(new BitmapDrawable(bitmap));
            }//from   w  w  w  .  j a  v a 2s  .  c  om
            return;
        }
    }

    AsyncHttpURLConnection httpConnection = new AsyncHttpURLConnection("GET", url, "",
            new AsyncHttpURLConnection.AsyncHttpEvents() {
                @Override
                public void onHttpError(String errorMessage) {
                    Log.d("LoadImage", errorMessage);
                }

                @Override
                public void onHttpComplete(String response) {
                    int size = 96;
                    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
                    Canvas canvas = new Canvas(bitmap);
                    final String trimmedName = name == null ? "" : name.trim();
                    drawTile(canvas, trimmedName, 0, 0, size, size);
                    ThumbnailsCacheManager.addBitmapToCache(url, bitmap);
                    onHttpComplete(bitmap);
                }

                @Override
                public void onHttpComplete(final Bitmap response) {
                    if (menuItemImage != null && menuItemImage.get() != null) {
                        uiHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                if (rounded) {
                                    RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory
                                            .create(mResources, response);
                                    roundedBitmap.setCircular(true);
                                    menuItemImage.get().setIcon(roundedBitmap);
                                } else {
                                    menuItemImage.get().setIcon(new BitmapDrawable(response));
                                }
                            }

                        });

                    }
                }

                private boolean drawTile(Canvas canvas, String letter, int tileColor, int left, int top,
                        int right, int bottom) {
                    letter = letter.toUpperCase(Locale.getDefault());
                    Paint tilePaint = new Paint(), textPaint = new Paint();
                    tilePaint.setColor(tileColor);
                    textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
                    textPaint.setColor(FG_COLOR);
                    textPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
                    textPaint.setTextSize((float) ((right - left) * 0.8));
                    Rect rect = new Rect();

                    canvas.drawRect(new Rect(left, top, right, bottom), tilePaint);
                    textPaint.getTextBounds(letter, 0, 1, rect);
                    float width = textPaint.measureText(letter);
                    canvas.drawText(letter, (right + left) / 2 - width / 2,
                            (top + bottom) / 2 + rect.height() / 2, textPaint);
                    return true;
                }

                private boolean drawTile(Canvas canvas, String name, int left, int top, int right, int bottom) {
                    if (name != null) {
                        final String letter = getFirstLetter(name);
                        final int color = ThumbnailsCacheManager.getColorForName(name);
                        drawTile(canvas, letter, color, left, top, right, bottom);
                        return true;
                    }
                    return false;
                }

            });
    httpConnection.setBitmap();
    httpConnection.send();
}

From source file:org.mariotaku.twidere.view.ShapedImageView.java

private void updateShadowBitmap() {
    if (useOutline())
        return;//from  w w w.  ja va 2 s.  c  om
    final int width = getWidth(), height = getHeight();
    if (width <= 0 || height <= 0)
        return;
    final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
            contentRight = width - getPaddingRight(), contentBottom = height - getPaddingBottom();
    final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
    final float radius = mShadowRadius, dy = radius * 1.5f / 2;
    final int size = Math.round(Math.min(contentWidth, contentHeight) + radius * 2);
    mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
    Canvas canvas = new Canvas(mShadowBitmap);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(0xFF000000 | mBackgroundPaint.getColor());
    paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
    final RectF rect = new RectF(radius, radius, size - radius, size - radius);
    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawOval(rect, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawOval(rect, paint);
    } else {
        final float cr = getCalculatedCornerRadius();
        canvas.drawRoundRect(rect, cr, cr, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawRoundRect(rect, cr, cr, paint);
    }
    invalidate();
}

From source file:org.getlantern.firetweet.view.ShapedImageView.java

private void updateShadowBitmap() {
    if (USE_OUTLINE)
        return;//from ww w.j  a va  2  s  .c  o  m
    final int width = getWidth(), height = getHeight();
    if (width <= 0 || height <= 0)
        return;
    final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
            contentRight = width - getPaddingRight(), contentBottom = height - getPaddingBottom();
    final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
    final float radius = mShadowRadius, dy = radius * 1.5f / 2;
    final int size = Math.round(Math.min(contentWidth, contentHeight) + radius * 2);
    mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
    Canvas canvas = new Canvas(mShadowBitmap);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(0xFF000000 | mBackgroundPaint.getColor());
    paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
    final RectF rect = new RectF(radius, radius, size - radius, size - radius);
    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawOval(rect, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawOval(rect, paint);
    } else {
        final float cr = getCalculatedCornerRadius();
        canvas.drawRoundRect(rect, cr, cr, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawRoundRect(rect, cr, cr, paint);
    }
    invalidate();
}

From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java

public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnTouchListener touchListener,
        View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener) {
    Resources res = launcher.getResources();
    mLauncher = launcher;/*from  ww w.  j av  a  2s.  com*/
    mApps = apps;
    mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
    mGridSizer = new GridSpanSizer();
    mGridLayoutMgr = new AppsGridLayoutManager(launcher);
    mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
    mItemDecoration = new GridItemDecoration();
    mLayoutInflater = LayoutInflater.from(launcher);
    mTouchListener = touchListener;
    mIconClickListener = iconClickListener;
    mIconLongClickListener = iconLongClickListener;
    mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
    mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset);
    mIsRtl = Utilities.isRtl(res);

    mSectionTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mSectionTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.all_apps_grid_section_text_size));
    mSectionTextPaint.setColor(res.getColor(R.color.all_apps_grid_section_text_color));

    mPredictedAppsDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPredictedAppsDividerPaint.setStrokeWidth(Utilities.pxFromDp(1f, res.getDisplayMetrics()));
    mPredictedAppsDividerPaint.setColor(0x1E000000);
    mPredictionBarDividerOffset = (-res.getDimensionPixelSize(R.dimen.all_apps_prediction_icon_bottom_padding)
            + res.getDimensionPixelSize(R.dimen.all_apps_icon_top_bottom_padding)) / 2;
}

From source file:com.amitupadhyay.aboutexample.util.CollapsingTextHelper.java

private void ensureExpandedTexture() {
    if (mExpandedTitleTexture != null || mExpandedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) {
        return;/*w w w .  ja  v a  2s  . c  o  m*/
    }
    mTextPaint.setTextSize(mExpandedTextSize);
    mTextPaint.setColor(mExpandedTextColor);
    mTextureAscent = mTextPaint.ascent();
    mTextureDescent = mTextPaint.descent();
    final int w = Math.round(mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()));
    final int h = Math.round(mTextureDescent - mTextureAscent);
    if (w <= 0 && h <= 0) {
        return; // If the width or height are 0, return
    }
    mExpandedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(mExpandedTitleTexture);
    c.drawText(mTextToDraw, 0, mTextToDraw.length(), 0, h - mTextPaint.descent(), mTextPaint);
    if (mTexturePaint == null) {
        // Make sure we have a paint
        mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    }
}

From source file:io.plaidapp.core.ui.transitions.ReflowText.java

private Layout createLayout(ReflowData data, Context context, boolean enforceMaxLines) {
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(data.textSize);/*w  w w  . j  a  v a2s. c  o  m*/
    paint.setColor(data.textColor);
    paint.setLetterSpacing(data.letterSpacing);
    if (data.fontResId != 0) {
        try {
            Typeface font = ResourcesCompat.getFont(context, data.fontResId);
            if (font != null) {
                paint.setTypeface(font);
            }
        } catch (Resources.NotFoundException nfe) {
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        StaticLayout.Builder builder = StaticLayout.Builder
                .obtain(data.text, 0, data.text.length(), paint, data.textWidth)
                .setLineSpacing(data.lineSpacingAdd, data.lineSpacingMult).setBreakStrategy(data.breakStrategy);
        if (enforceMaxLines && data.maxLines != -1) {
            builder.setMaxLines(data.maxLines);
            builder.setEllipsize(TextUtils.TruncateAt.END);
        }
        return builder.build();
    } else {
        return new StaticLayout(data.text, paint, data.textWidth, Layout.Alignment.ALIGN_NORMAL,
                data.lineSpacingMult, data.lineSpacingAdd, true);
    }
}

From source file:com.example.view.wheel.WheelView.java

/**
 * Initializes resources/* w w w. j av a  2  s  . c  o m*/
 */
private void initResourcesIfNecessary() {
    if (itemsPaint == null) {
        itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
        //itemsPaint.density = getResources().getDisplayMetrics().density;
        itemsPaint.setTextSize(BaseUtil.dp2px(context, TEXT_SIZE));
    }

    if (valuePaint == null) {
        valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG | Paint.DITHER_FLAG);
        //valuePaint.density = getResources().getDisplayMetrics().density;
        valuePaint.setTextSize(BaseUtil.dp2px(context, TEXT_SIZE));
        valuePaint.setColor(Color.BLUE);
        //   valuePaint.setShadowLayer(0.1f, 0, 0.1f, 0xFFC0C0C0);
    }
    if (linePaint == null) {
        linePaint = new Paint();
        linePaint.setColor(Color.parseColor("#FF6D4B"));
        linePaint.setStrokeWidth(10.0F);
    }
    if (centerDrawable == null) {
        centerDrawable = ContextCompat.getDrawable(context, R.drawable.wheel_val);
    }

    if (topShadow == null) {
        topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
    }

    if (bottomShadow == null) {
        bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
    }

    //setBackgroundResource(R.drawable.wheel_bg);
    setBackgroundColor(Color.WHITE);
}

From source file:com.owen.view.views.PieChart.java

/**
 * Initialize the control. This code is in a separate method so that it can be
 * called from both constructors./*from www  .  j av a2 s . co m*/
 */
private void init() {
    // Force the background to software rendering because otherwise the Blur
    // filter won't work.
    setLayerToSW(this);

    // Set up the paint for the label text
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(mTextColor);
    if (mTextHeight == 0) {
        mTextHeight = mTextPaint.getTextSize();
    } else {
        mTextPaint.setTextSize(mTextHeight);
    }

    // Set up the paint for the pie slices
    mPiePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPiePaint.setStyle(Paint.Style.FILL);
    mPiePaint.setTextSize(mTextHeight);

    // Set up the paint for the shadow
    mShadowPaint = new Paint(0);
    mShadowPaint.setColor(0xff101010);
    mShadowPaint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL));

    // Add a child view to draw the pie. Putting this in a child view
    // makes it possible to draw it on a separate hardware layer that rotates
    // independently
    mPieView = new PieView(getContext());
    addView(mPieView);
    mPieView.rotateTo(mPieRotation);

    // The pointer doesn't need hardware acceleration, but in order to show up
    // in front of the pie it also needs to be on a separate view.
    mPointerView = new PointerView(getContext());
    addView(mPointerView);

    // Set up an animator to animate the PieRotation property. This is used to
    // correct the pie's orientation after the user lets go of it.
    if (Build.VERSION.SDK_INT >= 11) {
        mAutoCenterAnimator = ObjectAnimator.ofInt(PieChart.this, "PieRotation", 0);

        // Add a listener to hook the onAnimationEnd event so that we can do
        // some cleanup when the pie stops moving.
        mAutoCenterAnimator.addListener(new Animator.AnimatorListener() {
            public void onAnimationStart(Animator animator) {
            }

            public void onAnimationEnd(Animator animator) {
                mPieView.decelerate();
            }

            public void onAnimationCancel(Animator animator) {
            }

            public void onAnimationRepeat(Animator animator) {
            }
        });
    }

    // Create a Scroller to handle the fling gesture.
    if (Build.VERSION.SDK_INT < 11) {
        mScroller = new Scroller(getContext());
    } else {
        mScroller = new Scroller(getContext(), null, true);
    }
    // The scroller doesn't have any built-in animation functions--it just supplies
    // values when we ask it to. So we have to have a way to call it every frame
    // until the fling ends. This code (ab)uses a ValueAnimator object to generate
    // a callback on every animation frame. We don't use the animated value at all.
    if (Build.VERSION.SDK_INT >= 11) {
        mScrollAnimator = ValueAnimator.ofFloat(0, 1);
        mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                tickScrollAnimation();
            }
        });
    }

    // Create a gesture detector to handle onTouch messages
    mDetector = new GestureDetector(PieChart.this.getContext(), new GestureListener());

    // Turn off long press--this control doesn't use it, and if long press is enabled,
    // you can't scroll for a bit, pause, then scroll some more (the pause is interpreted
    // as a long press, apparently)
    mDetector.setIsLongpressEnabled(false);

    // In edit mode it's nice to have some demo data, so add that here.
    if (this.isInEditMode()) {
        Resources res = getResources();
        addItem("Annabelle", 3, ContextCompat.getColor(getContext(), R.color.bluegrass));
        addItem("Brunhilde", 4, ContextCompat.getColor(getContext(), R.color.chartreuse));
        addItem("Carolina", 2, ContextCompat.getColor(getContext(), R.color.emerald));
        addItem("Dahlia", 3, ContextCompat.getColor(getContext(), R.color.seafoam));
        addItem("Ekaterina", 1, ContextCompat.getColor(getContext(), R.color.slate));
    }

}