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:com.fjoglar.etsitnoticias.view.widget.InkPageIndicator.java

public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final int density = (int) context.getResources().getDisplayMetrics().density;

    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0);

    dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density);
    dotRadius = dotDiameter / 2;/*ww w.j  ava2  s.c o m*/
    halfDotRadius = dotRadius / 2;
    gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density);
    animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION);
    animHalfDuration = animDuration / 2;
    unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR);
    selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor,
            DEFAULT_SELECTED_COLOUR);

    a.recycle();

    unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    unselectedPaint.setColor(unselectedColour);
    selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    selectedPaint.setColor(selectedColour);
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        interpolator = AnimUtils.getFastOutSlowInInterpolator(context);
    } else {
        interpolator = null;
    }

    // create paths & rect now  reuse & rewind later
    combinedUnselectedPath = new Path();
    unselectedDotPath = new Path();
    unselectedDotLeftPath = new Path();
    unselectedDotRightPath = new Path();
    rectF = new RectF();

    addOnAttachStateChangeListener(this);
}

From source file:com.microsoft.mimickeralarm.mimics.ProgressButton.java

private void prepareDrawStroke(int color) {
    mBrush.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBrush.setStyle(Paint.Style.STROKE);
    mBrush.setStrokeWidth(10f);/*  ww  w  .  ja va2 s.  c  o m*/
    mBrush.setColor(color);
}

From source file:com.andremion.music.MusicCoverView.java

public MusicCoverView(Context context, AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MusicCoverView);
    @Shape/* w  w  w  .  java2  s. com*/
    int shape = a.getInt(R.styleable.MusicCoverView_shape, SHAPE_SQUARE);
    @ColorInt
    int trackColor = a.getColor(R.styleable.MusicCoverView_trackColor, TRACK_COLOR);
    a.recycle();

    // TODO: Canvas.clipPath works wrong when running with hardware acceleration on Android N
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }

    final float density = getResources().getDisplayMetrics().density;
    mTrackSize = TRACK_SIZE * density;
    mTrackPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTrackPaint.setStyle(Paint.Style.STROKE);
    mTrackPaint.setStrokeWidth(TRACK_WIDTH * density);

    mDiscPaintCenterDecor = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscPaintCenterDecor.setStyle(Paint.Style.FILL);
    mDiscPaintCenter = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscPaintCenter.setStyle(Paint.Style.FILL);

    setShape(shape);
    setTrackColor(trackColor);
    if (getDrawable() != null && ((BitmapDrawable) getDrawable()).getBitmap() != null) {
        setCenterColor(DISC_CENTER_COLOR, Palette.generate(((BitmapDrawable) getDrawable()).getBitmap(), 32)
                .getLightVibrantColor(DISC_CENTER_DECOR_COLOR));
    } else {
        setCenterColor(DISC_CENTER_COLOR, DISC_CENTER_DECOR_COLOR);
    }
    setScaleType();

    mStartRotateAnimator = ObjectAnimator.ofFloat(this, View.ROTATION, 0, FULL_ANGLE);
    mStartRotateAnimator.setInterpolator(new LinearInterpolator());
    if (SHAPE_SQUARE == mShape) {
        mStartRotateAnimator.setDuration(DURATION_SQUARE);
    } else {
        mStartRotateAnimator.setDuration(DURATION);
        mStartRotateAnimator.setRepeatCount(Animation.INFINITE);
    }

    mStartRotateAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            float current = getRotation();
            float target = current > HALF_ANGLE ? FULL_ANGLE : 0; // Choose the shortest distance to 0 rotation
            float diff = target > 0 ? FULL_ANGLE - current : current;
            mEndRotateAnimator.setFloatValues(current, target);
            if (SHAPE_SQUARE == mShape) {
                mEndRotateAnimator.setDuration((int) (DURATION_SQUARE_PER_DEGREES * diff));
            } else {
                mEndRotateAnimator.setDuration((int) (DURATION_PER_DEGREES * diff));
            }

            mEndRotateAnimator.start();
        }
    });

    mEndRotateAnimator = ObjectAnimator.ofFloat(MusicCoverView.this, View.ROTATION, 0);
    mEndRotateAnimator.setInterpolator(new LinearInterpolator());
    mEndRotateAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            setRotation(0);
            // isRunning method return true if it's called form here.
            // So we need call from post method to get the right returning.
            post(new Runnable() {
                @Override
                public void run() {
                    if (mCallbacks != null) {
                        mCallbacks.onRotateEnd(MusicCoverView.this);
                    }
                }
            });
        }
    });

    mRectToCircleTransition = new MorphTransition(SHAPE_RECTANGLE);
    mRectToCircleTransition.addTarget(this);
    mRectToCircleTransition.addListener(new TransitionAdapter() {
        @Override
        public void onTransitionStart(Transition transition) {
            mIsMorphing = true;
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            mIsMorphing = false;
            mShape = SHAPE_CIRCLE;
            if (mCallbacks != null) {
                mCallbacks.onMorphEnd(MusicCoverView.this);
            }
        }
    });

    mCircleToRectTransition = new MorphTransition(SHAPE_CIRCLE);
    mCircleToRectTransition.addTarget(this);
    mCircleToRectTransition.addListener(new TransitionAdapter() {
        @Override
        public void onTransitionStart(Transition transition) {
            mIsMorphing = true;
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            mIsMorphing = false;
            mShape = SHAPE_RECTANGLE;
            if (mCallbacks != null) {
                mCallbacks.onMorphEnd(MusicCoverView.this);
            }
        }
    });

    mSquareToSquareTransition = new MorphTransition(SHAPE_SQUARE);
    mSquareToSquareTransition.addTarget(this);
    mSquareToSquareTransition.addListener(new TransitionAdapter() {
        @Override
        public void onTransitionStart(Transition transition) {
            mIsMorphing = true;
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            mIsMorphing = false;
            mShape = SHAPE_SQUARE;
            if (mCallbacks != null) {
                mCallbacks.onMorphEnd(MusicCoverView.this);
            }
        }
    });
}

From source file:com.sun.toy.widget.CalendarView.java

private Paint makePaint(int color) {
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(color);//  ww  w  . j  a  v a  2s  .  c om
    p.setTextSize(mDefaultTextSize);
    return p;
}

From source file:fr.francetv.zoom.share.loader.ZoomLoaderView.java

private void init() {
    mIsRunning = false;/*from   w w w . jav a  2 s .c o m*/

    mViewWidthPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, VIEW_WIDTH_DP,
            getResources().getDisplayMetrics());
    mViewHeightPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, VIEW_HEIGHT_DP,
            getResources().getDisplayMetrics());

    mRadiusPx = mViewHeightPx / 2;

    mMaskBitmap = Bitmap.createBitmap(mViewWidthPx, mViewHeightPx, Bitmap.Config.ARGB_8888);
    new Canvas(mMaskBitmap).drawBitmap(
            BitmapFactory.decodeResource(getContext().getResources(), R.drawable.img_loader_mask), 0, 0, null);

    mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mMaskPaint.setFilterBitmap(false);
    mMaskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setFilterBitmap(false);
    mBackgroundPaint.setXfermode(null);
    mBackgroundPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.darker_gray));

    // Circles
    mAnimPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mAnimPaint.setXfermode(null);
    mAnimPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.holo_green_light));

    mLeftCircleArc = new RectF(0, 0, 2 * mRadiusPx, 2 * mRadiusPx);
    mRightCircleArc = new RectF(mViewWidthPx - 2 * mRadiusPx, 0, mViewWidthPx, 2 * mRadiusPx);

    //Anims
    mAnimationIn = ValueAnimator.ofInt(0, 361 + LEFT_START_DEGRE);
    mAnimationIn.setInterpolator(new FastOutSlowInInterpolator());
    mAnimationIn.addUpdateListener(mAnimationInUpdateListener);
    mAnimationIn.addListener(mAnimationInListener);
    mAnimationIn.setDuration(ANIMATION_IN_DURATION_MS);

    mAnimationOut = ValueAnimator.ofInt(0, 361 + LEFT_START_DEGRE);
    mAnimationOut.setInterpolator(new FastOutSlowInInterpolator());
    mAnimationOut.addUpdateListener(mAnimationOutUpdateListener);
    mAnimationOut.addListener(mAnimationOutListener);
    mAnimationOut.setDuration(ANIMATION_OUT_DURATION_MS);

    mDelayHandler = new DelayHandler(mAnimationOut);
}

From source file:enterprayz.megatools.Tools.java

public static int getTextHeight(String text, int maxWidth, float textSize, Typeface typeface) {
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    paint.setTextSize(textSize);/*w w  w  . ja  va  2 s  .  c  o  m*/
    paint.setTypeface(typeface);

    int lineCount = 0;

    int index = 0;
    int length = text.length();

    while (index < length - 1) {
        index += paint.breakText(text, index, length, true, maxWidth, null);
        lineCount++;
    }

    Rect bounds = new Rect();
    paint.getTextBounds("Py", 0, 2, bounds);
    return (int) Math.floor(lineCount * bounds.height());
}

From source file:com.github.shareme.gwsinkpageindicator.library.InkPageIndicator.java

public InkPageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final int density = (int) context.getResources().getDisplayMetrics().density;

    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.InkPageIndicator, defStyle, 0);

    dotDiameter = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotDiameter, DEFAULT_DOT_SIZE * density);
    dotRadius = dotDiameter / 2;// w w w  .ja  va2  s.  c  o  m
    halfDotRadius = dotRadius / 2;
    gap = a.getDimensionPixelSize(R.styleable.InkPageIndicator_dotGap, DEFAULT_GAP * density);
    animDuration = (long) a.getInteger(R.styleable.InkPageIndicator_animationDuration, DEFAULT_ANIM_DURATION);
    animHalfDuration = animDuration / 2;
    unselectedColour = a.getColor(R.styleable.InkPageIndicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR);
    selectedColour = a.getColor(R.styleable.InkPageIndicator_currentPageIndicatorColor,
            DEFAULT_SELECTED_COLOUR);

    a.recycle();

    unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    unselectedPaint.setColor(unselectedColour);
    selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    selectedPaint.setColor(selectedColour);
    interpolator = new FastOutSlowInInterpolator();

    // create paths & rect now  reuse & rewind later
    combinedUnselectedPath = new Path();
    unselectedDotPath = new Path();
    unselectedDotLeftPath = new Path();
    unselectedDotRightPath = new Path();
    rectF = new RectF();

    addOnAttachStateChangeListener(this);
}

From source file:com.ez.gallery.ucrop.view.widget.HorizontalProgressWheelView.java

private void init() {
    mMiddleLineColor = ContextCompat.getColor(getContext(), R.color.ucrop_color_progress_wheel_line);

    mProgressLineWidth = getContext().getResources()
            .getDimensionPixelSize(R.dimen.ucrop_width_horizontal_wheel_progress_line);
    mProgressLineHeight = getContext().getResources()
            .getDimensionPixelSize(R.dimen.ucrop_height_horizontal_wheel_progress_line);
    mProgressLineMargin = getContext().getResources()
            .getDimensionPixelSize(R.dimen.ucrop_margin_horizontal_wheel_progress_line);

    mProgressLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mProgressLinePaint.setStyle(Paint.Style.STROKE);
    mProgressLinePaint.setStrokeWidth(mProgressLineWidth);

}

From source file:com.jams.music.player.GridViewFragment.GridViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.fragment_grid_view, container, false);
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;//from  w ww .j  a v a  2s  .c o m
    mFragment = this;

    //Set the background color and the partial color bleed.
    mRootView.setBackgroundColor(UIElementsHelper.getBackgroundColor(mContext));

    //Grab the fragment. This will determine which data to load into the cursor.
    mFragmentId = getArguments().getInt(Common.FRAGMENT_ID);
    mFragmentTitle = getArguments().getString(MainActivity.FRAGMENT_HEADER);
    mDBColumnsMap = new HashMap<Integer, String>();

    mQuickScroll = (QuickScrollGridView) mRootView.findViewById(R.id.quickscrollgrid);

    //Set the adapter for the outer gridview.
    mGridView = (GridView) mRootView.findViewById(R.id.generalGridView);
    mGridViewContainer = (RelativeLayout) mRootView.findViewById(R.id.fragment_grid_view_frontal_layout);
    mGridView.setVerticalScrollBarEnabled(false);

    //Set the number of gridview columns based on the screen density and orientation.
    if (mApp.isPhoneInLandscape() || mApp.isTabletInLandscape()) {
        mGridView.setNumColumns(4);
    } else if (mApp.isPhoneInPortrait()) {
        mGridView.setNumColumns(3);//Test only, 2
    } else if (mApp.isTabletInPortrait()) {
        mGridView.setNumColumns(3);
    }

    //KitKat translucent navigation/status bar.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int topPadding = Common.getStatusBarHeight(mContext);

        //Calculate navigation bar height.
        int navigationBarHeight = 0;
        int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            navigationBarHeight = getResources().getDimensionPixelSize(resourceId);
        }

        mGridViewContainer.setPadding(0, topPadding, 0, 0);
        mGridView.setClipToPadding(false);
        mGridView.setPadding(0, mGridView.getPaddingTop(), 0, navigationBarHeight);
        mQuickScroll.setPadding(0, 0, 0, navigationBarHeight);

    }

    //Set the empty views.
    mEmptyTextView = (TextView) mRootView.findViewById(R.id.empty_view_text);
    mEmptyTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Light"));
    mEmptyTextView
            .setPaintFlags(mEmptyTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;

    mHandler.postDelayed(queryRunnable, 250);
    return mRootView;
}

From source file:com.morninz.ninepinview.widget.NinePINView.java

public NinePINView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NinePINView);

    mPointColor = a.getColor(R.styleable.NinePINView_pointColor, DEFAULT_POINT_COLOR);
    mCircleColor = a.getColor(R.styleable.NinePINView_circleColor, DEFAULT_CIRCLE_COLOR);
    mLineColor = a.getColor(R.styleable.NinePINView_lineColor, DEFAULT_LINE_COLOR);
    mWrongColor = a.getColor(R.styleable.NinePINView_wrongColor, DEFAULT_WRONG_COLOR);

    mPointSize = a.getDimension(R.styleable.NinePINView_pointSize, 8.0f);
    mCircleWidth = a.getDimension(R.styleable.NinePINView_circleWidth, 5.0f);
    mLineWidth = a.getDimension(R.styleable.NinePINView_lineWidth, 5.0f);
    mCircleRadius = a.getDimension(R.styleable.NinePINView_circleRadius, 40.0f);

    a.recycle();//www.  j a  va2  s  .  c om

    // center point
    mPointPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPointPaint.setColor(mPointColor);
    mPointPaint.setStyle(Style.FILL);

    // circle
    mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaint.setColor(mCircleColor);
    mCirclePaint.setStrokeWidth(mCircleWidth);
    mCirclePaint.setStyle(Style.STROKE);

    // connection line
    mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLinePaint.setColor(mLineColor);
    mLinePaint.setStrokeWidth(mLineWidth);
    mLinePaint.setStyle(Style.FILL);
    mLinePaint.setStrokeCap(Cap.ROUND);
    mLinePaint.setStrokeJoin(Join.ROUND);

    // wrong triangle path
    mWrongPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mWrongPaint.setColor(mWrongColor);
    mWrongPaint.setStyle(Style.FILL);

    setPadding(Math.max(getPaddingLeft(), DEFAULT_PADDING), Math.max(getPaddingTop(), DEFAULT_PADDING),
            Math.max(getPaddingRight(), DEFAULT_PADDING), Math.max(getPaddingBottom(), DEFAULT_PADDING));

    mWillDrawWrongTriangle = false;
}