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:com.example.lsy.animationproject.CrossfadeActivity.java

/**
 * Cross-fades between {@link #mContentView} and {@link #mLoadingView}.
 *//*from  ww w .java  2s.  c  o m*/
/*
private void crossfade(boolean contentLoaded)
{
//set the content view to 0% opacity but visible
mContentView.setAlpha(0f);
mContentView.setVisibility(View.VISIBLE);
        
//animate the content view to 100% opacity, and clear the animation
//listener set on the view
mContentView.animate()
        .alpha(1f)
        .setDuration(mShortAnimationDuration)
        .setListener(null);
        
//animate the loading view to 0% opacity.
mLoadingView.animate()
        .alpha(0f)
        .setDuration(mShortAnimationDuration)
        .setListener(new AnimatorListenerAdapter() {
            @Override
            //After the animation ends, set its visibility to GONE
            public void onAnimationEnd(Animator animation) {
                mLoadingView.setVisibility(View.GONE);
            }
        });
} */
private void showContentOrLoadingIndicator(boolean contentLoaded) {
    // Decide which view to hide and which to show.
    final View showView = contentLoaded ? mContentView : mLoadingView;
    final View hideView = contentLoaded ? mLoadingView : mContentView;

    // Set the "show" view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    showView.setAlpha(0f);
    showView.setVisibility(View.VISIBLE);

    // Animate the "show" view to 100% opacity, and clear any animation listener set on
    // the view. Remember that listeners are not limited to the specific animation
    // describes in the chained method calls. Listeners are set on the
    // ViewPropertyAnimator object for the view, which persists across several
    // animations.
    showView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);

    // Animate the "hide" view to 0% opacity. After the animation ends, set its visibility
    // to GONE as an optimization step (it won't participate in layout passes, etc.)
    hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    hideView.setVisibility(View.GONE);
                }
            });
}

From source file:ua.yyunikov.android.view.AdditionRemovalListView.java

public void removeWithAnimation(final AdditionRemovalAdapter.Item item, final View itemView) {
    final ObjectAnimator anim = ObjectAnimator.ofFloat(itemView, View.ALPHA, 0);

    anim.setDuration(ANIMATION_TIME);//from  w w w  .  ja  va  2  s.c o m
    ViewCompat.setHasTransientState(itemView, true);

    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            remove(item);
            itemView.setAlpha(1);
            ViewCompat.setHasTransientState(itemView, false);
        }
    });
    anim.start();
}

From source file:com.granita.tasks.groupings.BaseTaskViewDescriptor.java

@SuppressLint("NewApi")
protected void resetFlingView(View view) {
    View flingContentView = getView(view, getFlingContentViewId());
    if (flingContentView == null) {
        flingContentView = view;//from w  w  w. j a va2s  .c  o m
    }

    if (android.os.Build.VERSION.SDK_INT >= 14) {
        if (flingContentView.getTranslationX() != 0) {
            flingContentView.setTranslationX(0);
            flingContentView.setAlpha(1);
        }
    } else {
        LayoutParams layoutParams = (LayoutParams) flingContentView.getLayoutParams();
        if (layoutParams.leftMargin != 0 || layoutParams.rightMargin != 0) {
            layoutParams.setMargins(0, layoutParams.topMargin, 0, layoutParams.bottomMargin);
            flingContentView.setLayoutParams(layoutParams);
        }
    }
}

From source file:com.aran.bang.widget.BaseTransformer.java

/**
 * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)} is called.
 *
 * @param view/*from w w  w .  j av  a  2 s  .co  m*/
 * @param position
 */
protected void onPreTransform(View view, float position) {
    final float width = view.getWidth();

    view.setRotationX(0);
    view.setRotationY(0);
    view.setRotation(0);
    view.setScaleX(1);
    view.setScaleY(1);
    view.setPivotX(0);
    view.setPivotY(0);
    view.setTranslationY(0);
    view.setTranslationX(isPagingEnabled() ? 0f : -width * position);

    if (hideOffscreenPages()) {
        view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
    } else {
        view.setAlpha(1f);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.node.rendition.CarouselPreviewFragment.java

public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();

    if (position < -1) { // [-Infinity,-1)
                         // This page is way off-screen to the left.
        view.setAlpha(0);

    } else if (position <= 0) { // [-1,0]
                                // Use the default slide transition when moving to the left page
        view.setAlpha(1);/* w  w  w . j  av a2  s.com*/
        view.setTranslationX(0);
        view.setScaleX(1);
        view.setScaleY(1);

    } else if (position <= 1) { // (0,1]
                                // Fade the page out.
        view.setAlpha(1 - position);

        // Counteract the default slide transition
        view.setTranslationX(pageWidth * -position);

        // Scale the page down (between MIN_SCALE and 1)
        float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);

    } else { // (1,+Infinity]
             // This page is way off-screen to the right.
        view.setAlpha(0);
    }
}

From source file:com.carver.paul.truesight.Ui.MainActivity.java

/**
 * Makes the camera pulse infinitely (will be stopped when loading completes)
 *///from w w  w.ja  va 2  s. c  om
//TODO-nextversion: Make camera do something other than pulse - it implies you should press
// it!
private void pulseCameraImage() {
    //Code using the old Animation class, rather than the new ViewPropertyAnimator
    //Infinite repeat is easier to implement this way

    View cameraImage = findViewById(R.id.image_pulsing_camera);
    cameraImage.setVisibility(View.VISIBLE);
    cameraImage.setAlpha(1f);

    ScaleAnimation pulse = new ScaleAnimation(1f, 0.8f, 1f, 0.8f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    pulse.setDuration(250);
    pulse.setRepeatCount(Animation.INFINITE);
    pulse.setRepeatMode(Animation.REVERSE);
    cameraImage.startAnimation(pulse);

    View processingText = findViewById(R.id.text_processing_image);
    processingText.setAlpha(1f);
    processingText.setVisibility(View.VISIBLE);
}

From source file:us.phyxsi.gameshelf.ui.HomeActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case RC_SEARCH:
        // reset the search icon which we hid
        View searchMenuView = toolbar.findViewById(R.id.menu_search);
        if (searchMenuView != null) {
            searchMenuView.setAlpha(1f);
        }/*  w  w w .  ja  v a 2s .  c  om*/
        break;
    case RC_ADD_NEW_BOARDGAME:
        if (resultCode == AddNewBoardgame.RESULT_BOARDGAME_ADDED) {
            dataManager.loadFromDatabase();
        }
        break;
    case RC_IMPORT:
        break;
    }
}

From source file:com.cesards.samples.cropimageview.ABaseTransformer.java

/**
 * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View,
 * float)}.//from   w w w. j  a v a2 s.c  o  m
 * <p>
 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
 * alpha.
 *
 * @param page Apply the transformation to this page
 * @param position Position of page relative to the current front-and-center position of the pager. 0 is front and
 * center. 1 is one full page position to the right, and -1 is one page position to the left.
 */
protected void onPreTransform(View page, float position) {
    final float width = page.getWidth();

    page.setRotationX(0);
    page.setRotationY(0);
    page.setRotation(0);
    page.setScaleX(1);
    page.setScaleY(1);
    page.setPivotX(0);
    page.setPivotY(0);
    page.setTranslationY(0);
    page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

    if (hideOffscreenPages()) {
        page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
    } else {
        page.setAlpha(1f);
    }
}

From source file:com.charbgr.BlurNavigationDrawer.v4.BlurActionBarDrawerToggle.java

private void setAlpha(View view, float alpha, long durationMillis) {
    if (Build.VERSION.SDK_INT < 11) {
        final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
        animation.setDuration(durationMillis);
        animation.setFillAfter(true);//from www .  j a v a 2  s.c om
        view.startAnimation(animation);
    } else {
        view.setAlpha(alpha);
    }
}

From source file:com.runmit.sweedee.view.flippablestackview.StackPageTransformer.java

@Override
public void transformPage(View view, float position) {
    int dimen = view.getHeight();

    if (!mInitialValuesCalculated) {
        mInitialValuesCalculated = true;
        calculateInitialValues(dimen);/*w ww .  j av  a2 s.  c o  m*/
    }

    view.setRotationX(0);
    view.setPivotY(dimen / 2f);
    view.setPivotX(view.getWidth() / 2f);

    if (position < -mNumberOfStacked - 1) {
        view.setAlpha(0f);
    } else if (position <= 0) {
        float scale = mZeroPositionScale + (position * mStackedScaleFactor);
        float baseTranslation = (-position * dimen);
        float shiftTranslation = calculateShiftForScale(position, scale, dimen);
        view.setScaleX(scale);
        view.setScaleY(scale);
        view.setAlpha(1.0f + (position * mAlphaFactor));
        Log.d("position", "baseTranslation=" + baseTranslation + ",shiftTranslation=" + shiftTranslation
                + ",transY=" + (baseTranslation + shiftTranslation));
        view.setTranslationY(baseTranslation + shiftTranslation);
    } else if (position <= 1) {
        view.bringToFront();
        float baseTranslation = position * dimen;
        float scale = mZeroPositionScale
                - mValueInterpolator.map(mScaleInterpolator.getInterpolation(position));
        scale = (scale < 0) ? 0f : scale;
        float shiftTranslation = (1.0f - position) * mOverlap;
        float rotation = -mRotationInterpolator.getInterpolation(position) * 90;
        rotation = (rotation < -90) ? -90 : rotation;
        float alpha = 1.0f - position;
        alpha = (alpha < 0) ? 0f : alpha;
        view.setAlpha(alpha);
        view.setPivotY(dimen);
        view.setRotationX(rotation);
        view.setScaleX(mZeroPositionScale);
        view.setScaleY(scale);
        view.setTranslationY(-baseTranslation - mBelowStackSpace - shiftTranslation);
    } else if (position > 1) {
        view.setAlpha(0f);
    }
}