Example usage for android.graphics.drawable Drawable setAlpha

List of usage examples for android.graphics.drawable Drawable setAlpha

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setAlpha.

Prototype

public abstract void setAlpha(@IntRange(from = 0, to = 255) int alpha);

Source Link

Document

Specify an alpha value for the drawable.

Usage

From source file:com.github.takahirom.plaidanimation.transition.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Rect fabBounds = fromFab ? startBounds : endBounds;
    final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }/*from   www  .  j a  va  2s . c  o m*/

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(new FastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(new LinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setOutlineProvider(new ViewOutlineProvider() {
                    @Override
                    public void getOutline(View view, Outline outline) {
                        final int left = (view.getWidth() - fabBounds.width()) / 2;
                        final int top = (view.getHeight() - fabBounds.height()) / 2;
                        outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height());
                        view.setClipToOutline(true);
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Work around issue with elevation shadows. At the end of the return transition the shared
    // element's shadow is drawn twice (by each activity) which is jarring. This workaround
    // still causes the shadow to snap, but it's better than seeing it double drawn.
    Animator elevation = null;
    if (!fromFab) {
        elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
        elevation.setDuration(duration);
        elevation.setInterpolator(fastOutSlowInInterpolator);
    }

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (elevation != null)
        transition.play(elevation);
    if (fromFab) {
        transition.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Clean up
                view.getOverlay().clear();
            }
        });
    }
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Rect fabBounds = fromFab ? startBounds : endBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils
            .getFastOutSlowInInterpolator(sceneRoot.getContext());
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }/*from   w  w w.  j a  va  2 s  . c om*/

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(sceneRoot.getContext()));
        //circularReveal.setInterpolator(new AnimationUtils().loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext()));

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setOutlineProvider(new ViewOutlineProvider() {
                    @Override
                    public void getOutline(View view, Outline outline) {
                        final int left = (view.getWidth() - fabBounds.width()) / 2;
                        final int top = (view.getHeight() - fabBounds.height()) / 2;
                        outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height());
                        view.setClipToOutline(true);
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Work around issue with elevation shadows. At the end of the return transition the shared
    // element's shadow is drawn twice (by each activity) which is jarring. This workaround
    // still causes the shadow to snap, but it's better than seeing it double drawn.
    Animator elevation = null;
    if (!fromFab) {
        elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
        elevation.setDuration(duration);
        elevation.setInterpolator(fastOutSlowInInterpolator);
    }

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (elevation != null)
        transition.play(elevation);
    if (fromFab) {
        transition.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Clean up
                view.getOverlay().clear();
            }
        });
    }
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:com.n3rditorium.pocketdoggie.transitions.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }/*from w w  w. j a v a2s  . c  o m*/

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Rect fabBounds = fromFab ? startBounds : endBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils
            .getFastOutSlowInInterpolator(sceneRoot.getContext());
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab) {
        fabColor.setAlpha(0);
    }
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab) {
        fabIcon.setAlpha(0);
    }
    view.getOverlay().add(fabIcon);

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.width() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(sceneRoot.getContext()));
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.width() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext()));

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setOutlineProvider(new ViewOutlineProvider() {
                    @Override
                    public void getOutline(View view, Outline outline) {
                        final int left = (view.getWidth() - fabBounds.width()) / 2;
                        final int top = (view.getHeight() - fabBounds.height()) / 2;
                        outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height());
                        view.setClipToOutline(true);
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Work around issue with elevation shadows. At the end of the return transition the shared
    // element's shadow is drawn twice (by each activity) which is jarring. This workaround
    // still causes the shadow to snap, but it's better than seeing it double drawn.
    Animator elevation = null;
    if (!fromFab) {
        elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
        elevation.setDuration(duration);
        elevation.setInterpolator(fastOutSlowInInterpolator);
    }

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (elevation != null) {
        transition.play(elevation);
    }
    if (fromFab) {
        transition.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Clean up
                view.getOverlay().clear();
            }
        });
    }
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:org.mariotaku.twidere.fragment.support.UserFragment.java

private static void setCompatToolbarOverlayAlpha(FragmentActivity activity, float alpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return;//from   w  ww  . j av a  2  s.  co m
    final View windowOverlay = activity.findViewById(R.id.window_overlay);
    if (windowOverlay != null) {
        windowOverlay.setAlpha(alpha);
        return;
    }
    final Drawable drawable = ThemeUtils.getCompatToolbarOverlay(activity);
    if (drawable == null)
        return;
    drawable.setAlpha(Math.round(alpha * 255));
}

From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }//from  w  w  w  .java 2 s  . c o m

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Since the view that's being transition to always seems to be on the top (z-order), we have
    // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
    // There has to be another way to do this, right?
    Drawable dialogView = null;
    if (!fromFab) {
        startValues.view.setDrawingCacheEnabled(true);
        startValues.view.buildDrawingCache();
        Bitmap viewBitmap = startValues.view.getDrawingCache();
        dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
        dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
        view.getOverlay().add(dialogView);
    }

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();

                view.setOutlineProvider(new ViewOutlineProvider() {
                    boolean hasRun = false;

                    @Override
                    public void getOutline(final View view, Outline outline) {
                        final int left = (view.getWidth() - endBounds.width()) / 2;
                        final int top = (view.getHeight() - endBounds.height()) / 2;

                        outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());

                        if (!hasRun) {
                            hasRun = true;
                            view.setClipToOutline(true);

                            // We have to remove this as soon as it's laid out so we can get the shadow back
                            view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (view.getWidth() == endBounds.width()
                                            && view.getHeight() == endBounds.height()) {
                                        view.setOutlineProvider(fabOutlineProvider);
                                        view.setClipToOutline(false);
                                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                                        return true;
                                    }

                                    return true;
                                }
                            });
                        }
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (dialogView != null) {
        final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0)
                .setDuration(twoThirdsDuration);
        dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
        transition.playTogether(dialogViewFade);
    }
    transition.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // Clean up
            view.getOverlay().clear();

            if (!fromFab) {
                view.setTranslationX(0);
                view.setTranslationY(0);
                view.setTranslationZ(0);

                view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY),
                        makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
                view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
            }

        }
    });
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:com.guerinet.formgenerator.TextViewFormItem.java

/**
 * Builds the view and adds it to the container
 *
 * @return The {@link TextViewFormItem} instance
 *//*from www .  j  a  v a  2s  .co m*/
@CallSuper
public TextViewFormItem build() {
    Drawable[] drawables = new Drawable[4];
    // Get all of the icons
    drawables[0] = getDrawable(icons[0]);
    drawables[1] = getDrawable(icons[1]);
    drawables[2] = getDrawable(icons[2]);
    drawables[3] = getDrawable(icons[3]);

    // Set the compound drawable padding
    if (fg.builder.defaultDrawablePaddingSize != -1) {
        textView.setCompoundDrawablePadding(fg.builder.defaultDrawablePaddingSize);
    }

    // Set the correct tinting and alpha
    for (int i = 0; i < 4; i++) {
        Icon icon = icons[i];
        Drawable drawable = drawables[i];
        if (drawable != null) {
            // Wrap it in the design support library
            drawable = DrawableCompat.wrap(drawable.mutate());
            if (!icon.visible) {
                drawable.setAlpha(0);
            } else if (icon.color != -1) {
                DrawableCompat.setTint(drawable, icon.color);
            }
        }
    }

    // Set the drawables on the view
    textView.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], drawables[2], drawables[3]);

    // Add the view to the container
    fg.container.addView(view);
    return this;
}

From source file:co.taqat.call.assistant.AssistantActivity.java

public void displayRemoteProvisioningInProgressDialog() {
    remoteProvisioningInProgress = true;

    progress = ProgressDialog.show(this, null, null);
    Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorE));
    d.setAlpha(200);
    progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
    progress.getWindow().setBackgroundDrawable(d);
    progress.setContentView(R.layout.progress_dialog);
    progress.show();//from   w ww. jav  a 2s  . c om
}

From source file:co.taqat.call.assistant.AssistantActivity.java

public void displayRegistrationInProgressDialog() {
    if (LinphoneManager.getLc().isNetworkReachable()) {
        progress = ProgressDialog.show(this, null, null);
        Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorE));
        d.setAlpha(200);
        progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT);
        progress.getWindow().setBackgroundDrawable(d);
        progress.setContentView(R.layout.progress_dialog);
        progress.show();//from w  w w  .ja va  2  s .c  om
    }
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static void setDrawableOpacity(final Drawable drawable, final float opacity) {
    if (drawable instanceof ColorDrawable || drawable instanceof TiBackgroundDrawable) {
        drawable.setAlpha(Math.round(opacity * 255));
    } else if (drawable != null) {
        drawable.setColorFilter(createColorFilterForOpacity(opacity));
    }// w  w w . ja  va 2  s.c o m
}

From source file:org.linphone.AccountPreferencesFragment.java

private void initAccountPreferencesFields(PreferenceScreen parent) {
    boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n;

    accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(),
            LinphonePreferences.instance().getXmlrpcUrl());
    accountCreator.setListener(this);

    PreferenceCategory account = (PreferenceCategory) getPreferenceScreen()
            .findPreference(getString(R.string.pref_sipaccount_key));
    EditTextPreference username = (EditTextPreference) account.getPreference(0);
    username.setOnPreferenceChangeListener(usernameChangedListener);
    if (!isNewAccount) {
        username.setText(mPrefs.getAccountUsername(n));
        username.setSummary(username.getText());
    }/*from   w w w  .j  a va  2  s  .c  om*/

    EditTextPreference userid = (EditTextPreference) account.getPreference(1);
    userid.setOnPreferenceChangeListener(useridChangedListener);
    if (!isNewAccount) {
        userid.setText(mPrefs.getAccountUserId(n));
        userid.setSummary(userid.getText());
    }

    EditTextPreference password = (EditTextPreference) account.getPreference(2);
    password.setOnPreferenceChangeListener(passwordChangedListener);
    if (!isNewAccount) {
        password.setText(mPrefs.getAccountPassword(n));
    }

    EditTextPreference domain = (EditTextPreference) account.getPreference(3);
    domain.setOnPreferenceChangeListener(domainChangedListener);
    if (!isNewAccount) {
        domain.setText(mPrefs.getAccountDomain(n));
        domain.setSummary(domain.getText());
    }

    EditTextPreference displayName = (EditTextPreference) account.getPreference(4);
    displayName.setOnPreferenceChangeListener(displayNameChangedListener);
    if (!isNewAccount) {
        displayName.setText(mPrefs.getAccountDisplayName(n));
        displayName.setSummary(displayName.getText());
    }

    PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen()
            .findPreference(getString(R.string.pref_advanced_key));
    mTransportPreference = (ListPreference) advanced.getPreference(0);
    initializeTransportPreference(mTransportPreference);
    mTransportPreference.setOnPreferenceChangeListener(transportChangedListener);
    if (!isNewAccount) {
        mTransportPreference.setSummary(mPrefs.getAccountTransportString(n));
    }

    mProxyPreference = (EditTextPreference) advanced.getPreference(1);
    mProxyPreference.setOnPreferenceChangeListener(proxyChangedListener);
    if (!isNewAccount) {
        mProxyPreference.setText(mPrefs.getAccountProxy(n));
        mProxyPreference
                .setSummary("".equals(mProxyPreference.getText()) || (mProxyPreference.getText() == null)
                        ? getString(R.string.pref_help_proxy)
                        : mProxyPreference.getText());
    }

    CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(2);
    outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener);
    if (!isNewAccount) {
        outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n));
    }

    EditTextPreference expires = (EditTextPreference) advanced.getPreference(3);
    expires.setOnPreferenceChangeListener(expiresChangedListener);
    if (!isNewAccount) {
        expires.setText(mPrefs.getExpires(n));
        expires.setSummary(mPrefs.getExpires(n));
    }

    EditTextPreference prefix = (EditTextPreference) advanced.getPreference(4);
    prefix.setOnPreferenceChangeListener(prefixChangedListener);
    if (!isNewAccount) {
        String prefixValue = mPrefs.getPrefix(n);
        prefix.setText(prefixValue);
        prefix.setSummary(prefixValue);
    }

    CheckBoxPreference avpf = (CheckBoxPreference) advanced.getPreference(5);
    avpf.setOnPreferenceChangeListener(avpfChangedListener);
    if (!isNewAccount) {
        avpf.setChecked(mPrefs.avpfEnabled(n));
    }

    EditTextPreference avpfRRInterval = (EditTextPreference) advanced.getPreference(6);
    avpfRRInterval.setOnPreferenceChangeListener(avpfRRIntervalChangedListener);
    if (!isNewAccount) {
        avpfRRInterval.setText(mPrefs.getAvpfRRInterval(n));
        avpfRRInterval.setSummary(mPrefs.getAvpfRRInterval(n));
    }

    CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(7);
    escape.setOnPreferenceChangeListener(escapeChangedListener);
    if (!isNewAccount) {
        escape.setChecked(mPrefs.getReplacePlusByZeroZero(n));
    }

    Preference linkAccount = advanced.getPreference(8);
    linkAccount.setOnPreferenceClickListener(linkAccountListener);

    PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen()
            .findPreference(getString(R.string.pref_manage_key));
    final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0);
    disable.setEnabled(true);
    disable.setOnPreferenceChangeListener(disableChangedListener);
    if (!isNewAccount) {
        disable.setChecked(!mPrefs.isAccountEnabled(n));
    }

    CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1);
    mainAccount.setChecked(isDefaultAccount);
    mainAccount.setEnabled(!mainAccount.isChecked());
    mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            mPrefs.setDefaultAccount(n);
            disable.setEnabled(false);
            disable.setChecked(false);
            preference.setEnabled(false);
            return true;
        }
    });
    if (!isNewAccount) {
        mainAccount.setEnabled(!mainAccount.isChecked());
    }

    final Preference changePassword = manage.getPreference(2);
    if (mPrefs.getAccountDomain(n).compareTo(getString(R.string.default_domain)) == 0) {
        changePassword.setEnabled(!isNewAccount);
        changePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                final AlertDialog.Builder alert = new AlertDialog.Builder(LinphoneActivity.instance());
                LayoutInflater inflater = LinphoneActivity.instance().getLayoutInflater();
                View layout = inflater.inflate(R.layout.new_password, null);
                final EditText pass1 = (EditText) layout.findViewById(R.id.password1);
                final EditText pass2 = (EditText) layout.findViewById(R.id.password2);
                alert.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        LinphoneAccountCreator.PasswordCheck status = accountCreator
                                .setPassword(pass1.getText().toString());
                        if (status.equals(LinphoneAccountCreator.PasswordCheck.Ok)) {
                            if (pass1.getText().toString().compareTo(pass2.getText().toString()) == 0) {
                                accountCreator.setUsername(mPrefs.getAccountUsername(n));
                                accountCreator.setHa1(mPrefs.getAccountHa1(n));
                                LinphoneAccountCreator.RequestStatus req_status = accountCreator
                                        .updatePassword(pass1.getText().toString());
                                if (!req_status.equals(LinphoneAccountCreator.RequestStatus.Ok)) {
                                    LinphoneUtils.displayErrorAlert(
                                            LinphoneUtils.errorForRequestStatus(req_status),
                                            LinphoneActivity.instance());
                                } else {
                                    progress = ProgressDialog.show(LinphoneActivity.instance(), null, null);
                                    Drawable d = new ColorDrawable(ContextCompat
                                            .getColor(LinphoneActivity.instance(), R.color.colorE));
                                    d.setAlpha(200);
                                    progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                                            WindowManager.LayoutParams.MATCH_PARENT);
                                    progress.getWindow().setBackgroundDrawable(d);
                                    progress.setContentView(R.layout.progress_dialog);
                                    progress.show();
                                }
                            } else {
                                LinphoneUtils.displayErrorAlert(getString(R.string.wizard_passwords_unmatched),
                                        LinphoneActivity.instance());
                            }
                            return;
                        }
                        LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForPasswordStatus(status),
                                LinphoneActivity.instance());
                    }
                });

                alert.setView(layout);
                alert.show();
                return true;
            }
        });
    } else {
        changePassword.setEnabled(false);
    }

    final Preference delete = manage.getPreference(3);
    delete.setEnabled(!isNewAccount);
    delete.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            mPrefs.deleteAccount(n);
            LinphoneActivity.instance().refreshAccounts();
            LinphoneActivity.instance().displaySettings();
            return true;
        }
    });
}