Example usage for android.view View getAlpha

List of usage examples for android.view View getAlpha

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "drawing")
public float getAlpha() 

Source Link

Document

The opacity of the view.

Usage

From source file:com.n2hsu.launcher.Page.java

private Runnable createPostDeleteAnimationRunnable(final View dragView) {
    return new Runnable() {
        @Override/*from ww  w  .  j  av  a 2s. c  o m*/
        public void run() {
            int dragViewIndex = indexOfChild(dragView);

            // For each of the pages around the drag view, animate them from
            // the previous
            // position to the new position in the layout (as a result of
            // the drag view moving
            // in the layout)
            // NOTE: We can make an assumption here because we have
            // side-bound pages that we
            // will always have pages to animate in from the left
            getOverviewModePages(mTempVisiblePagesRange);
            boolean isLastWidgetPage = (mTempVisiblePagesRange[0] == mTempVisiblePagesRange[1]);
            boolean slideFromLeft = (isLastWidgetPage || dragViewIndex > mTempVisiblePagesRange[0]);

            // Setup the scroll to the correct page before we swap the views
            if (slideFromLeft) {
                snapToPageImmediately(dragViewIndex - 1);
            }

            int firstIndex = (isLastWidgetPage ? 0 : mTempVisiblePagesRange[0]);
            int lastIndex = Math.min(mTempVisiblePagesRange[1], getPageCount() - 1);
            int lowerIndex = (slideFromLeft ? firstIndex : dragViewIndex + 1);
            int upperIndex = (slideFromLeft ? dragViewIndex - 1 : lastIndex);
            ArrayList<Animator> animations = new ArrayList<Animator>();
            for (int i = lowerIndex; i <= upperIndex; ++i) {
                View v = getChildAt(i);
                // dragViewIndex < pageUnderPointIndex, so after we remove
                // the
                // drag view all subsequent views to pageUnderPointIndex
                // will
                // shift down.
                int oldX = 0;
                int newX = 0;
                if (slideFromLeft) {
                    if (i == 0) {
                        // Simulate the page being offscreen with the page
                        // spacing
                        oldX = getViewportOffsetX() + getChildOffset(i) - getChildWidth(i) - mPageSpacing;
                    } else {
                        oldX = getViewportOffsetX() + getChildOffset(i - 1);
                    }
                    newX = getViewportOffsetX() + getChildOffset(i);
                } else {
                    oldX = getChildOffset(i) - getChildOffset(i - 1);
                    newX = 0;
                }

                // Animate the view translation from its old position to its
                // new
                // position
                AnimatorSet anim = (AnimatorSet) v.getTag();
                if (anim != null) {
                    anim.cancel();
                }

                // Note: Hacky, but we want to skip any optimizations to not
                // draw completely
                // hidden views
                v.setAlpha(Math.max(v.getAlpha(), 0.01f));
                v.setTranslationX(oldX - newX);
                anim = new AnimatorSet();
                anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f),
                        ObjectAnimator.ofFloat(v, "alpha", 1f));
                animations.add(anim);
                v.setTag(ANIM_TAG_KEY, anim);
            }

            AnimatorSet slideAnimations = new AnimatorSet();
            slideAnimations.playTogether(animations);
            slideAnimations.setDuration(DELETE_SLIDE_IN_SIDE_PAGE_DURATION);
            slideAnimations.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mDeferringForDelete = false;
                    onEndReordering();
                    onRemoveViewAnimationCompleted();
                }
            });
            slideAnimations.start();

            removeView(dragView);
            onRemoveView(dragView, true);
        }
    };
}

From source file:org.telegram.ui.ChannelAdminLogActivity.java

private void updateMessagesVisisblePart() {
    if (chatListView == null) {
        return;/*from   w w w . ja va 2  s.c  om*/
    }
    int count = chatListView.getChildCount();
    int height = chatListView.getMeasuredHeight();
    int minPositionHolder = Integer.MAX_VALUE;
    int minPositionDateHolder = Integer.MAX_VALUE;
    View minDateChild = null;
    View minChild = null;
    View minMessageChild = null;
    boolean foundTextureViewMessage = false;
    for (int a = 0; a < count; a++) {
        View view = chatListView.getChildAt(a);
        if (view instanceof ChatMessageCell) {
            ChatMessageCell messageCell = (ChatMessageCell) view;
            int top = messageCell.getTop();
            int bottom = messageCell.getBottom();
            int viewTop = top >= 0 ? 0 : -top;
            int viewBottom = messageCell.getMeasuredHeight();
            if (viewBottom > height) {
                viewBottom = viewTop + height;
            }
            messageCell.setVisiblePart(viewTop, viewBottom - viewTop);

            MessageObject messageObject = messageCell.getMessageObject();
            if (roundVideoContainer != null && messageObject.isRoundVideo()
                    && MediaController.getInstance().isPlayingMessage(messageObject)) {
                ImageReceiver imageReceiver = messageCell.getPhotoImage();
                roundVideoContainer.setTranslationX(imageReceiver.getImageX());
                roundVideoContainer
                        .setTranslationY(fragmentView.getPaddingTop() + top + imageReceiver.getImageY());
                fragmentView.invalidate();
                roundVideoContainer.invalidate();
                foundTextureViewMessage = true;
            }
        }
        if (view.getBottom() <= chatListView.getPaddingTop()) {
            continue;
        }
        int position = view.getBottom();
        if (position < minPositionHolder) {
            minPositionHolder = position;
            if (view instanceof ChatMessageCell || view instanceof ChatActionCell) {
                minMessageChild = view;
            }
            minChild = view;
        }
        if (view instanceof ChatActionCell && ((ChatActionCell) view).getMessageObject().isDateObject) {
            if (view.getAlpha() != 1.0f) {
                view.setAlpha(1.0f);
            }
            if (position < minPositionDateHolder) {
                minPositionDateHolder = position;
                minDateChild = view;
            }
        }
    }
    if (roundVideoContainer != null) {
        if (!foundTextureViewMessage) {
            roundVideoContainer.setTranslationY(-AndroidUtilities.roundMessageSize - 100);
            fragmentView.invalidate();
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.isRoundVideo() && checkTextureViewPosition) {
                MediaController.getInstance().setCurrentVideoVisible(false);
            }
        } else {
            MediaController.getInstance().setCurrentVideoVisible(true);
        }
    }
    if (minMessageChild != null) {
        MessageObject messageObject;
        if (minMessageChild instanceof ChatMessageCell) {
            messageObject = ((ChatMessageCell) minMessageChild).getMessageObject();
        } else {
            messageObject = ((ChatActionCell) minMessageChild).getMessageObject();
        }
        floatingDateView.setCustomDate(messageObject.messageOwner.date);
    }
    currentFloatingDateOnScreen = false;
    currentFloatingTopIsNotMessage = !(minChild instanceof ChatMessageCell
            || minChild instanceof ChatActionCell);
    if (minDateChild != null) {
        if (minDateChild.getTop() > chatListView.getPaddingTop() || currentFloatingTopIsNotMessage) {
            if (minDateChild.getAlpha() != 1.0f) {
                minDateChild.setAlpha(1.0f);
            }
            hideFloatingDateView(!currentFloatingTopIsNotMessage);
        } else {
            if (minDateChild.getAlpha() != 0.0f) {
                minDateChild.setAlpha(0.0f);
            }
            if (floatingDateAnimation != null) {
                floatingDateAnimation.cancel();
                floatingDateAnimation = null;
            }
            if (floatingDateView.getTag() == null) {
                floatingDateView.setTag(1);
            }
            if (floatingDateView.getAlpha() != 1.0f) {
                floatingDateView.setAlpha(1.0f);
            }
            currentFloatingDateOnScreen = true;
        }
        int offset = minDateChild.getBottom() - chatListView.getPaddingTop();
        if (offset > floatingDateView.getMeasuredHeight()
                && offset < floatingDateView.getMeasuredHeight() * 2) {
            floatingDateView.setTranslationY(-floatingDateView.getMeasuredHeight() * 2 + offset);
        } else {
            floatingDateView.setTranslationY(0);
        }
    } else {
        hideFloatingDateView(true);
        floatingDateView.setTranslationY(0);
    }
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Add animators for animating out stale views
 * @param animationOutMode The animation mode to play for stale views
 *///  www .j a va2  s  .c  o  m
private void addOutAnimatorsForStaleViews(List<Animator> animators, AnimationOut animationOutMode) {
    if (animationOutMode == AnimationOut.NONE) {
        return;
    }

    for (final View v : mViewsToAnimateOut) {
        // For each stale view to animate out, retrieve the animators for the view, then attach
        // the StaleViewAnimationEndListener which checks to see if the view should be recycled
        // at the end of the animation.
        final List<Animator> viewAnimators = new ArrayList<Animator>();

        switch (animationOutMode) {
        case SLIDE:
            final LayoutParams lp = (LayoutParams) v.getLayoutParams();
            // Bias towards sliding right, but depending on the column that this view
            // is laid out in, slide towards the nearest side edge.
            int endTranslation = (int) (v.getWidth() * 1.5);
            if (lp.column < (mColCount / 2)) {
                endTranslation = -endTranslation;
            }
            SgvAnimationHelper.addSlideOutAnimators(viewAnimators, v, (int) v.getTranslationX(),
                    endTranslation);
            break;

        case COLLAPSE:
            SgvAnimationHelper.addCollapseOutAnimators(viewAnimators, v);
            break;

        case FLY_DOWN:
            SgvAnimationHelper.addFlyOutAnimators(viewAnimators, v, (int) v.getTranslationY(), getHeight());
            break;

        case FADE:
            SgvAnimationHelper.addFadeAnimators(viewAnimators, v, v.getAlpha(), 0 /* end alpha */);
            break;

        default:
            throw new IllegalStateException("Unknown animationOutMode: " + animationOutMode);
        }

        if (viewAnimators.size() > 0) {
            addStaleViewAnimationEndListener(v, viewAnimators);
            animators.addAll(viewAnimators);
        }
    }
}

From source file:com.deepak.myclock.widget.sgv.StaggeredGridView.java

/**
 * Add animators for animating out stale views
 * @param animationOutMode The animation mode to play for stale views
 *//*from  ww  w .j  a v  a 2  s .c om*/
private void addOutAnimatorsForStaleViews(List<Animator> animators,
        SgvAnimationHelper.AnimationOut animationOutMode) {
    if (animationOutMode == SgvAnimationHelper.AnimationOut.NONE) {
        return;
    }

    for (final View v : mViewsToAnimateOut) {
        // For each stale view to animate out, retrieve the animators for the view, then attach
        // the StaleViewAnimationEndListener which checks to see if the view should be recycled
        // at the end of the animation.
        final List<Animator> viewAnimators = new ArrayList<Animator>();

        switch (animationOutMode) {
        case SLIDE:
            final LayoutParams lp = (LayoutParams) v.getLayoutParams();
            // Bias towards sliding right, but depending on the column that this view
            // is laid out in, slide towards the nearest side edge.
            int endTranslation = (int) (v.getWidth() * 1.5);
            if (lp.column < (mColCount / 2)) {
                endTranslation = -endTranslation;
            }
            SgvAnimationHelper.addSlideOutAnimators(viewAnimators, v, (int) v.getTranslationX(),
                    endTranslation);
            break;

        case COLLAPSE:
            SgvAnimationHelper.addCollapseOutAnimators(viewAnimators, v);
            break;

        case FLY_DOWN:
            SgvAnimationHelper.addFlyOutAnimators(viewAnimators, v, (int) v.getTranslationY(), getHeight());
            break;

        case FADE:
            SgvAnimationHelper.addFadeAnimators(viewAnimators, v, v.getAlpha(), 0 /* end alpha */);
            break;

        default:
            throw new IllegalStateException("Unknown animationOutMode: " + animationOutMode);
        }

        if (viewAnimators.size() > 0) {
            addStaleViewAnimationEndListener(v, viewAnimators);
            animators.addAll(viewAnimators);
        }
    }
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

private void startEditFragment(final View view, final int position) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);//from   www . j  av a  2s. c  o m
    listAdapter.saveData();

    Source dataItem = listAdapter.getItem(position);
    final SourceInfoFragment sourceInfoFragment = new SourceInfoFragment();
    sourceInfoFragment.setImageDrawable(((ImageView) view.findViewById(R.id.source_image)).getDrawable());
    Bundle arguments = new Bundle();
    arguments.putInt("position", position);
    arguments.putString("type", dataItem.getType());
    arguments.putString("title", dataItem.getTitle());
    arguments.putString("data", dataItem.getData());
    arguments.putInt("num", dataItem.getNum());
    arguments.putBoolean("use", dataItem.isUse());
    arguments.putBoolean("preview", dataItem.isPreview());
    String imageFileName = dataItem.getImageFile().getAbsolutePath();
    if (imageFileName != null && imageFileName.length() > 0) {
        arguments.putString("image", imageFileName);
    } else {
        arguments.putString("image", "");
    }

    arguments.putBoolean("use_time", dataItem.isUseTime());
    arguments.putString("time", dataItem.getTime());

    sourceInfoFragment.setArguments(arguments);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final CardView sourceCard = (CardView) view.findViewById(R.id.source_card);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float cardStartShadow = sourceCard.getPaddingLeft();
    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final int viewStartPadding = view.getPaddingLeft();
    final float textStartX = sourceTitle.getX();
    final float textStartY = sourceTitle.getY();
    final float textTranslationY = sourceTitle.getHeight(); /*+ TypedValue.applyDimension(
                                                            TypedValue.COMPLEX_UNIT_DIP,
                                                            8,
                                                            getResources().getDisplayMetrics());*/

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, sourceInfoFragment, "source_info_fragment")
                        .addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            int newPadding = Math.round(viewStartPadding * (1 - interpolatedTime));
            int newShadowPadding = (int) (cardStartShadow * (1.0f - interpolatedTime));
            sourceCard.setShadowPadding(newShadowPadding, 0, newShadowPadding, 0);
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).topMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).bottomMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).leftMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).rightMargin = newShadowPadding;
            view.setPadding(newPadding, 0, newPadding, 0);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (screenHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            sourceTitle.setY(textStartY + interpolatedTime * textTranslationY);
            sourceTitle.setX(textStartX + viewStartPadding - newPadding);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            sourceTitle.getCurrentTextColor(), getResources().getColor(R.color.BLUE_OPAQUE));
    titleColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setTextColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleShadowAlphaAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getColorFilterInt(appContext), getResources().getColor(android.R.color.transparent));
    titleShadowAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setShadowLayer(4, 0, 0, (Integer) animation.getAnimatedValue());
        }
    });

    ValueAnimator imageOverlayAlphaAnimation = ValueAnimator.ofFloat(imageOverlay.getAlpha(), 0f);
    imageOverlayAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            imageOverlay.setAlpha((Float) animation.getAnimatedValue());
        }
    });

    int transitionTime = INFO_ANIMATION_TIME;

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(transitionTime);
    cardColorAnimation.setDuration(transitionTime);
    titleColorAnimation.setDuration(transitionTime);
    titleShadowAlphaAnimation.setDuration(transitionTime);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);
    titleColorAnimation.setInterpolator(decelerateInterpolator);
    titleShadowAlphaAnimation.setInterpolator(decelerateInterpolator);

    if (imageOverlay.getAlpha() > 0) {
        imageOverlayAlphaAnimation.start();
    }

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }
    }, (long) (transitionTime * 1.1f));

    needsListReset = true;
    view.startAnimation(animation);
    cardColorAnimation.start();
    titleColorAnimation.start();
    titleShadowAlphaAnimation.start();
}