Example usage for android.view View setAlpha

List of usage examples for android.view View setAlpha

Introduction

In this page you can find the example usage for android.view View setAlpha.

Prototype

public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) 

Source Link

Document

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static ViewPropertyAnimator fadeOut(final View from, int duration) {
    if (from.getVisibility() == View.VISIBLE) {
        from.clearAnimation();/*from w w  w  . j a  v a 2s .  c o  m*/
        final ViewPropertyAnimator animator = from.animate();
        animator.alpha(0f).setDuration(duration).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                from.setVisibility(View.INVISIBLE);
                from.setAlpha(1f);
            }
        });
        return animator;
    }
    return null;
}

From source file:Main.java

public static void fadeAnimation(final View view, final float fromAlpha, final float toAlpha, long duration,
        final Runnable callback) {
    Animation anim = new AlphaAnimation(fromAlpha, toAlpha);
    anim.setDuration(duration);/*from w  w  w . j a v  a  2s .  c o  m*/
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.setAlpha(toAlpha);
            if (toAlpha > 0)
                view.setVisibility(View.VISIBLE);
            else
                view.setVisibility(View.GONE);

            if (callback != null)
                callback.run();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });

    view.setVisibility(View.VISIBLE);
    view.startAnimation(anim);
}

From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java

/**
 * Makes sliding from the bottom effect on elements in a RecyclerView.
 * @param context from which call is made.
 * @param viewGroup on which to perform the animation.
 *///ww  w.java  2s .  c o  m
public static void animateViewsIn(Context context, ViewGroup viewGroup) {
    if (viewGroup != null) {
        int count = viewGroup.getChildCount();
        float offset = context.getResources().getDimensionPixelSize(R.dimen.offset_y);

        Interpolator interpolator;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            interpolator = AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in);
        } else {
            interpolator = AnimationUtils.loadInterpolator(context, android.R.interpolator.linear);
        }

        // loop over the children setting an increasing translation y but the same animation
        // duration + interpolation
        for (int i = 0; i < count; i++) {
            View view = viewGroup.getChildAt(i);
            view.setVisibility(View.VISIBLE);
            view.setTranslationY(offset);
            view.setAlpha(0.85f);
            // then animate back to natural position
            view.animate().translationY(0f).alpha(1f).setInterpolator(interpolator).setDuration(300L).start();
            // increase the offset distance for the next view
            offset *= 1.5f;
        }
    }
}

From source file:com.silentcircle.common.util.ViewUtil.java

/**
 * Sets view's opacity./*from www  .j  av a  2s  .c o m*/
 *
 * @param view View to set opacity to.
 * @param alpha The opacity of the view.
 *
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setAlpha(View view, float alpha) {
    if (view != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setAlpha(alpha);
    }
}

From source file:il.ac.shenkar.todos.view.MainActivity.java

/** 
 * Shows the undo task deletion window.//from   ww  w.  ja  va  2 s.c o m
 * 
 * @param viewContainer
 */
public static void showUndo(final View viewContainer) {
    viewContainer.setVisibility(View.VISIBLE);
    viewContainer.setAlpha(1);
    viewContainer.animate().alpha(0.4f).setDuration(5000).withEndAction(new Runnable() {
        @Override
        public void run() {
            viewContainer.setVisibility(View.GONE);
        }
    });
}

From source file:Main.java

public static Bitmap convertViewToBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;/*from  w  w  w.  j a  v  a2  s.c  o  m*/
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

        boolean willNotCache = comBitmap.willNotCacheDrawing();
        comBitmap.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = comBitmap.getDrawingCacheBackgroundColor();
        comBitmap.setDrawingCacheBackgroundColor(0);
        float alpha = comBitmap.getAlpha();
        comBitmap.setAlpha(1.0f);

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(0, 0, width, height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap + ")", new RuntimeException());
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}

From source file:de.teammartens.android.wattfinder.worker.AnimationWorker.java

public static void fadeIn(final View V, Integer offset, Float Alpha) {
    if (V == null)
        return;//from w  w  w  . j a v  a  2s .c o  m
    if (V.getVisibility() == View.GONE) {
        V.setAlpha(0f);
        V.setVisibility(View.VISIBLE);
    }
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        V.animate().setStartDelay(offset)

                .alpha(Alpha).setDuration(500).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        V.setVisibility(View.VISIBLE);
                        V.bringToFront();
                    }
                });
    } else {
        V.animate()

                .alpha(Alpha).setDuration(500).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        V.setVisibility(View.VISIBLE);
                        V.bringToFront();
                    }
                });
    }
}

From source file:net.huannguyen.conductorexample.transition.DetailPushAnimChangeHandler.java

@Override
protected void resetFromView(@NonNull View from) {
    from.setAlpha(1);
}

From source file:com.suyonoion.easystlviewpagerui.CubeOutTransformer.java

public void transformPage(View view, float position) {
    final float rotation = (position < 0 ? 90f : -90f) * Math.abs(position);
    view.setAlpha(rotation > 90f || rotation < -90f ? 0f : 1f);
    view.setPivotX(position < 0f ? view.getWidth() : 0f);
    view.setPivotY(view.getHeight() * 0.5f);
    view.setRotationY(90f * position);//www.  j  a va2s.c  o  m
}

From source file:com.google.android.leanbackjank.presenter.HeaderItemPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
    mUnselectedAlpha = viewGroup.getResources().getFraction(R.fraction.lb_browse_header_unselect_alpha, 1, 1);
    LayoutInflater inflater = (LayoutInflater) viewGroup.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.header_item, null);
    view.setAlpha(mUnselectedAlpha); // Initialize icons to be at half-opacity.

    return new ViewHolder(view);
}