Search in sources :

Example 36 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project Timber by naman14.

the class PlayTransition method createAnimator.

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    Rect startBounds = (Rect) startValues.values.get(PROPERTY_BOUNDS);
    Rect endBounds = (Rect) endValues.values.get(PROPERTY_BOUNDS);
    if (startBounds == null || endBounds == null || startBounds.equals(endBounds)) {
        return null;
    }
    Bitmap startImage = (Bitmap) startValues.values.get(PROPERTY_IMAGE);
    Drawable startBackground = new BitmapDrawable(sceneRoot.getContext().getResources(), startImage);
    final View startView = addViewToOverlay(sceneRoot, startImage.getWidth(), startImage.getHeight(), startBackground);
    Drawable shrinkingBackground = new ColorDrawable(mColor);
    final View shrinkingView = addViewToOverlay(sceneRoot, startImage.getWidth(), startImage.getHeight(), shrinkingBackground);
    int[] sceneRootLoc = new int[2];
    sceneRoot.getLocationInWindow(sceneRootLoc);
    int[] startLoc = (int[]) startValues.values.get(PROPERTY_POSITION);
    int startTranslationX = startLoc[0] - sceneRootLoc[0];
    int startTranslationY = startLoc[1] - sceneRootLoc[1];
    startView.setTranslationX(startTranslationX);
    startView.setTranslationY(startTranslationY);
    shrinkingView.setTranslationX(startTranslationX);
    shrinkingView.setTranslationY(startTranslationY);
    final View endView = endValues.view;
    float startRadius = calculateMaxRadius(shrinkingView);
    int minRadius = Math.min(calculateMinRadius(shrinkingView), calculateMinRadius(endView));
    ShapeDrawable circleBackground = new ShapeDrawable(new OvalShape());
    circleBackground.getPaint().setColor(mColor);
    final View circleView = addViewToOverlay(sceneRoot, minRadius * 2, minRadius * 2, circleBackground);
    float circleStartX = startLoc[0] - sceneRootLoc[0] + ((startView.getWidth() - circleView.getWidth()) / 2);
    float circleStartY = startLoc[1] - sceneRootLoc[1] + ((startView.getHeight() - circleView.getHeight()) / 2);
    circleView.setTranslationX(circleStartX);
    circleView.setTranslationY(circleStartY);
    circleView.setVisibility(View.INVISIBLE);
    shrinkingView.setAlpha(0f);
    endView.setAlpha(0f);
    Animator shrinkingAnimator = createCircularReveal(shrinkingView, startRadius, minRadius);
    shrinkingAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            shrinkingView.setVisibility(View.INVISIBLE);
            startView.setVisibility(View.INVISIBLE);
            circleView.setVisibility(View.VISIBLE);
        }
    });
    Animator startAnimator = createCircularReveal(startView, startRadius, minRadius);
    Animator fadeInAnimator = ObjectAnimator.ofFloat(shrinkingView, View.ALPHA, 0, 1);
    AnimatorSet shrinkFadeSet = new AnimatorSet();
    shrinkFadeSet.playTogether(shrinkingAnimator, startAnimator, fadeInAnimator);
    int[] endLoc = (int[]) endValues.values.get(PROPERTY_POSITION);
    float circleEndX = endLoc[0] - sceneRootLoc[0] + ((endView.getWidth() - circleView.getWidth()) / 2);
    float circleEndY = endLoc[1] - sceneRootLoc[1] + ((endView.getHeight() - circleView.getHeight()) / 2);
    Path circlePath = getPathMotion().getPath(circleStartX, circleStartY, circleEndX, circleEndY);
    Animator circleAnimator = ObjectAnimator.ofFloat(circleView, View.TRANSLATION_X, View.TRANSLATION_Y, circlePath);
    final View growingView = addViewToOverlay(sceneRoot, endView.getWidth(), endView.getHeight(), shrinkingBackground);
    growingView.setVisibility(View.INVISIBLE);
    float endTranslationX = endLoc[0] - sceneRootLoc[0];
    float endTranslationY = endLoc[1] - sceneRootLoc[1];
    growingView.setTranslationX(endTranslationX);
    growingView.setTranslationY(endTranslationY);
    float endRadius = calculateMaxRadius(endView);
    circleAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            circleView.setVisibility(View.INVISIBLE);
            growingView.setVisibility(View.VISIBLE);
            endView.setAlpha(1f);
        }
    });
    Animator fadeOutAnimator = ObjectAnimator.ofFloat(growingView, View.ALPHA, 1, 0);
    Animator endAnimator = createCircularReveal(endView, minRadius, endRadius);
    Animator growingAnimator = createCircularReveal(growingView, minRadius, endRadius);
    growingAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            sceneRoot.getOverlay().remove(startView);
            sceneRoot.getOverlay().remove(shrinkingView);
            sceneRoot.getOverlay().remove(circleView);
            sceneRoot.getOverlay().remove(growingView);
        }
    });
    AnimatorSet growingFadeSet = new AnimatorSet();
    growingFadeSet.playTogether(fadeOutAnimator, endAnimator, growingAnimator);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playSequentially(shrinkFadeSet, circleAnimator, growingFadeSet);
    return animatorSet;
}
Also used : Path(android.graphics.Path) Rect(android.graphics.Rect) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View) Bitmap(android.graphics.Bitmap) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 37 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project Timber by naman14.

the class TextDrawable method drawBorder.

private void drawBorder(Canvas canvas) {
    RectF rect = new RectF(getBounds());
    rect.inset(borderThickness / 2, borderThickness / 2);
    if (shape instanceof OvalShape) {
        canvas.drawOval(rect, borderPaint);
    } else if (shape instanceof RoundRectShape) {
        canvas.drawRoundRect(rect, radius, radius, borderPaint);
    } else {
        canvas.drawRect(rect, borderPaint);
    }
}
Also used : RectF(android.graphics.RectF) RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 38 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project wire-android by wireapp.

the class ConversationQuickMenu method setAccentColor.

public void setAccentColor(int color) {
    conversationButton.setAccentColor(color);
    ShapeDrawable ovalBackground = new ShapeDrawable(new OvalShape());
    ovalBackground.getPaint().setColor(color);
    ovalBackground.getPaint().setStyle(Paint.Style.FILL);
    ovalBackground.getPaint().setAntiAlias(true);
    cameraButton.setBackground(ovalBackground);
    callButton.setBackground(ovalBackground);
    videoCallButton.setBackground(ovalBackground);
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 39 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.

the class ColorChooserDialog method createSelector.

private Drawable createSelector(int color) {
    ShapeDrawable coloredCircle = new ShapeDrawable(new OvalShape());
    coloredCircle.getPaint().setColor(color);
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(shiftColor(color));
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { -android.R.attr.state_pressed }, coloredCircle);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerCircle);
    return stateListDrawable;
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 40 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.

the class FloatingActionButton method createCircleDrawable.

/**
     * 绘制一个drawable出来
     *
     * @param color
     * @param strokeWidth
     * @return
     */
private Drawable createCircleDrawable(int color, float strokeWidth) {
    //拿到alpha
    int alpha = Color.alpha(color);
    //拿到rgb
    int opaqueColor = opaque(color);
    //圆
    ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());
    //笔
    final Paint paint = fillDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setColor(opaqueColor);
    Drawable[] layers = { fillDrawable, createInnerStrokesDrawable(opaqueColor, strokeWidth) };
    //将Drawable[] layers 合成 LayerDrawable drawable
    LayerDrawable drawable = (alpha == 255 || !mStrokeVisible) ? new LayerDrawable(layers) : new TranslucentLayerDrawable(alpha, layers);
    //一半的描边宽度
    int halfStrokeWidth = (int) (strokeWidth / 2f);
    //描边的drawable
    drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
    //返回这个drawable
    return drawable;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

OvalShape (android.graphics.drawable.shapes.OvalShape)48 ShapeDrawable (android.graphics.drawable.ShapeDrawable)44 Paint (android.graphics.Paint)20 SuppressLint (android.annotation.SuppressLint)12 ColorDrawable (android.graphics.drawable.ColorDrawable)9 StateListDrawable (android.graphics.drawable.StateListDrawable)9 LayerDrawable (android.graphics.drawable.LayerDrawable)8 Drawable (android.graphics.drawable.Drawable)6 ImageView (android.widget.ImageView)5 LinearGradient (android.graphics.LinearGradient)4 Shader (android.graphics.Shader)4 ShaderFactory (android.graphics.drawable.ShapeDrawable.ShaderFactory)4 View (android.view.View)3 Bitmap (android.graphics.Bitmap)2 Rect (android.graphics.Rect)2 RectF (android.graphics.RectF)2 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 LinearInterpolator (android.view.animation.LinearInterpolator)2 RelativeLayout (android.widget.RelativeLayout)2