Java Code Examples for androidx.core.view.ViewCompat#setAlpha()

The following examples show how to use androidx.core.view.ViewCompat#setAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyPageTransform.java    From android with MIT License 6 votes vote down vote up
@Override
public void transformPage(View page, float position) {
    float scale = (position < 0)
            ? ((1 - SCALE_MAX) * position + 1)
            : ((SCALE_MAX - 1) * position + 1);
    float alpha = (position < 0)
            ? ((1 - ALPHA_MAX) * position + 1)
            : ((ALPHA_MAX - 1) * position + 1);
    //为了滑动过程中,page间距不变,这里做了处理
    if (position < 0) {
        ViewCompat.setPivotX(page, page.getWidth());
        ViewCompat.setPivotY(page, page.getHeight() / 2);
    } else {
        ViewCompat.setPivotX(page, 0);
        ViewCompat.setPivotY(page, page.getHeight() / 2);
    }
    ViewCompat.setScaleX(page, scale);
    ViewCompat.setScaleY(page, scale);
    ViewCompat.setAlpha(page, Math.abs(alpha));
}
 
Example 2
Source File: TSnackbar.java    From TSnackBar with Apache License 2.0 6 votes vote down vote up
void animateChildrenIn(int delay, int duration) {
    ViewCompat.setAlpha(mMessageView, 0f);
    ViewCompat.animate(mMessageView)
            .alpha(1f)
            .setDuration(duration)
            .setStartDelay(delay)
            .start();

    if (mActionView.getVisibility() == VISIBLE) {
        ViewCompat.setAlpha(mActionView, 0f);
        ViewCompat.animate(mActionView)
                .alpha(1f)
                .setDuration(duration)
                .setStartDelay(delay)
                .start();
    }
}
 
Example 3
Source File: TSnackbar.java    From TSnackBar with Apache License 2.0 6 votes vote down vote up
void animateChildrenOut(int delay, int duration) {
    ViewCompat.setAlpha(mMessageView, 1f);
    ViewCompat.animate(mMessageView)
            .alpha(0f)
            .setDuration(duration)
            .setStartDelay(delay)
            .start();

    if (mActionView.getVisibility() == VISIBLE) {
        ViewCompat.setAlpha(mActionView, 1f);
        ViewCompat.animate(mActionView)
                .alpha(0f)
                .setDuration(duration)
                .setStartDelay(delay)
                .start();
    }
}
 
Example 4
Source File: PagerSlidingTabStrip.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 6 votes vote down vote up
private void addTab(final int position, CharSequence title, View tabView) {
    TextView textView = (TextView) tabView.findViewById(R.id.tab_title);
    if (textView != null) {
        if (title != null) textView.setText(title);
        float alpha = pager.getCurrentItem() == position ? tabTextSelectedAlpha : tabTextAlpha;
        ViewCompat.setAlpha(textView, alpha);
    }

    tabView.setFocusable(true);
    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pager.getCurrentItem() != position) {
                View tab = tabsContainer.getChildAt(pager.getCurrentItem());
                notSelected(tab);
                pager.setCurrentItem(position);
            } else if (tabReselectedListener != null) {
                tabReselectedListener.onTabReselected(position);
            }
        }
    });

    tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
 
Example 5
Source File: BaseItemAnimator.java    From recyclerview-animators with Apache License 2.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
  boolean oldItem = false;
  if (changeInfo.newHolder == item) {
    changeInfo.newHolder = null;
  } else if (changeInfo.oldHolder == item) {
    changeInfo.oldHolder = null;
    oldItem = true;
  } else {
    return false;
  }
  ViewCompat.setAlpha(item.itemView, 1);
  ViewCompat.setTranslationX(item.itemView, 0);
  ViewCompat.setTranslationY(item.itemView, 0);
  dispatchChangeFinished(item, oldItem);
  return true;
}
 
Example 6
Source File: IModeActivity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
public void transformPage(View view, float position) {
    if (position < -1) {

    } else if (position <= 0) {
        ViewCompat.setTranslationX(view, -view.getWidth() * position);

        ViewCompat.setPivotX(view, view.getWidth() * 0.5f);
        ViewCompat.setPivotY(view, view.getHeight() * 0.5f);
        ViewCompat.setScaleX(view, 1 + position);
        ViewCompat.setScaleY(view, 1 + position);

        if (position < -0.95f) {
            ViewCompat.setAlpha(view, 0);
        } else {
            ViewCompat.setAlpha(view, 1);
        }
    } else if (position <= 1) {
        ViewCompat.setTranslationX(view, -view.getWidth() * position);

        ViewCompat.setPivotX(view, view.getWidth() * 0.5f);
        ViewCompat.setPivotY(view, view.getHeight() * 0.5f);
        ViewCompat.setScaleX(view, 1 - position);
        ViewCompat.setScaleY(view, 1 - position);

        if (position > 0.95f) {
            ViewCompat.setAlpha(view, 0);
        } else {
            ViewCompat.setAlpha(view, 1);
        }
    }
}
 
Example 7
Source File: CustomTextInputLayout.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public void setHelperText(CharSequence helperText) {
  this.helperText = helperText;
  if (!this.helperTextEnabled) {
    if (TextUtils.isEmpty(helperText)) {
      return;
    }
    this.setHelperTextEnabled(true);
  }

  if (!TextUtils.isEmpty(helperText)) {
    this.helperView.setText(helperText);
    this.helperView.setVisibility(View.VISIBLE);
    ViewCompat.setAlpha(this.helperView, 0.0F);
    ViewCompat.animate(this.helperView)
        .alpha(1.0F)
        .setDuration(200L)
        .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
        .setListener(null)
        .start();
  } else if (this.helperView.getVisibility() == VISIBLE) {
    ViewCompat.animate(this.helperView)
        .alpha(0.0F)
        .setDuration(200L)
        .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
        .setListener(new ViewPropertyAnimatorListenerAdapter() {
          public void onAnimationEnd(View view) {
            helperView.setText(null);
            helperView.setVisibility(INVISIBLE);
          }
        })
        .start();
  }
  this.sendAccessibilityEvent(2048);
}
 
Example 8
Source File: SnackBarView.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
private void init() {
    View.inflate(getContext(), R.layout.ef_imagepikcer_snackbar, this);
    if (isInEditMode()) {
        return;
    }
    ViewCompat.setAlpha(this, 0f);

    int padding = getContext().getResources().getDimensionPixelSize(R.dimen.ef_spacing_double);
    setPadding(padding, 0, padding, 0);

    txtCaption = findViewById(R.id.ef_snackbar_txt_bottom_caption);
    btnAction = findViewById(R.id.ef_snackbar_btn_action);
}
 
Example 9
Source File: SwipeListViewTouchListener.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * Will delete all pending dismisses.
 * Will call callback onDismiss for all pending dismisses.
 * Will reset all cell height to originalHeight.
 *
 * @param originalHeight is the height of the cell before animation.
 */
private void removePendingDismisses(int originalHeight) {
    // No active animations, process all pending dismisses.
    // Sort by descending position
    Collections.sort(pendingDismisses);

    int[] dismissPositions = new int[pendingDismisses.size()];
    for (int i = pendingDismisses.size() - 1; i >= 0; i--) {
        dismissPositions[i] = pendingDismisses.get(i).position;
    }
    swipeListView.onDismiss(dismissPositions);

    ViewGroup.LayoutParams lp;
    for (PendingDismissData pendingDismiss : pendingDismisses) {
        // Reset view presentation
        if (pendingDismiss.view != null) {
            ViewCompat.setAlpha(pendingDismiss.view, 1f);
            ViewCompat.setTranslationX(pendingDismiss.view, 0);
            lp = pendingDismiss.view.getLayoutParams();
            lp.height = originalHeight;
            pendingDismiss.view.setLayoutParams(lp);
        }
    }

    resetPendingDismisses();

}
 
Example 10
Source File: PagerSlidingTabStrip.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
private void notSelected(View tab) {
    if (tab != null) {
        TextView title = (TextView) tab.findViewById(R.id.tab_title);
        if (title != null) {
            title.setTypeface(tabTypeface, tabTypefaceStyle);
            ViewCompat.setAlpha(title, tabTextAlpha);
        }
    }
}
 
Example 11
Source File: ViewHelper.java    From recyclerview-animators with Apache License 2.0 5 votes vote down vote up
public static void clear(View v) {
  ViewCompat.setAlpha(v, 1);
  ViewCompat.setScaleY(v, 1);
  ViewCompat.setScaleX(v, 1);
  ViewCompat.setTranslationY(v, 0);
  ViewCompat.setTranslationX(v, 0);
  ViewCompat.setRotation(v, 0);
  ViewCompat.setRotationY(v, 0);
  ViewCompat.setRotationX(v, 0);
  ViewCompat.setPivotY(v, v.getMeasuredHeight() / 2);
  ViewCompat.setPivotX(v, v.getMeasuredWidth() / 2);
  ViewCompat.animate(v).setInterpolator(null).setStartDelay(0);
}
 
Example 12
Source File: BaseItemAnimator.java    From recyclerview-animators with Apache License 2.0 5 votes vote down vote up
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
  if (oldHolder == newHolder) {
    // Don't know how to run change animations when the same view holder is re-used.
    // run a move animation to handle position changes.
    return animateMove(oldHolder, fromX, fromY, toX, toY);
  }
  final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
  final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
  final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
  endAnimation(oldHolder);
  int deltaX = (int) (toX - fromX - prevTranslationX);
  int deltaY = (int) (toY - fromY - prevTranslationY);
  // recover prev translation state after ending animation
  ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
  ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
  ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
  if (newHolder != null && newHolder.itemView != null) {
    // carry over translation values
    endAnimation(newHolder);
    ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
    ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
    ViewCompat.setAlpha(newHolder.itemView, 0);
  }
  mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
  return true;
}
 
Example 13
Source File: LandingAnimator.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
  ViewCompat.setAlpha(holder.itemView, 0);
  ViewCompat.setScaleX(holder.itemView, 1.5f);
  ViewCompat.setScaleY(holder.itemView, 1.5f);
}
 
Example 14
Source File: FadeInAnimator.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
  ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 15
Source File: FadeInDownAnimator.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
  ViewCompat.setTranslationY(holder.itemView, -holder.itemView.getHeight() * .25f);
  ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 16
Source File: FadeInUpAnimator.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
  ViewCompat.setTranslationY(holder.itemView, holder.itemView.getHeight() * .25f);
  ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 17
Source File: SlideInDownAnimator.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
  ViewCompat.setTranslationY(holder.itemView, -holder.itemView.getHeight());
  ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 18
Source File: FadeInRightAnimator.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
  ViewCompat.setTranslationX(holder.itemView, holder.itemView.getRootView().getWidth() * .25f);
  ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 19
Source File: FadeInLeftAnimator.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
  ViewCompat.setTranslationX(holder.itemView, -holder.itemView.getRootView().getWidth() * .25f);
  ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 20
Source File: SwipeListViewTouchListener.java    From UltimateRecyclerView with Apache License 2.0 4 votes vote down vote up
/**
 * Moves the view
 *
 * @param deltaX delta
 */
public void move(float deltaX) {
    swipeListView.onMove(downPosition, deltaX);
    float posX = ViewCompat.getX(frontView);
    if (opened.get(downPosition)) {
        posX += openedRight.get(downPosition) ? -viewWidth + rightOffset : viewWidth - leftOffset;
    }
    if (posX > 0 && !swipingRight) {
        if (SwipeListView.DEBUG) {
            Log.d(SwipeListView.TAG, "change to right");
        }
        swipingRight = !swipingRight;
        swipeCurrentAction = swipeActionRight;
        if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
            backView.setVisibility(View.GONE);
        } else {
            backView.setVisibility(View.VISIBLE);
        }
    }
    if (posX < 0 && swipingRight) {
        if (SwipeListView.DEBUG) {
            Log.d(SwipeListView.TAG, "change to left");
        }
        swipingRight = !swipingRight;
        swipeCurrentAction = swipeActionLeft;
        if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
            backView.setVisibility(View.GONE);
        } else {
            backView.setVisibility(View.VISIBLE);
        }
    }
    if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_DISMISS) {
        ViewCompat.setTranslationX(parentView, deltaX);
        ViewCompat.setAlpha(parentView, Math.max(0f, Math.min(1f,
                1f - 2f * Math.abs(deltaX) / viewWidth)));
    } else if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
        if ((swipingRight && deltaX > 0 && posX < DISPLACE_CHOICE)
                || (!swipingRight && deltaX < 0 && posX > -DISPLACE_CHOICE)
                || (swipingRight && deltaX < DISPLACE_CHOICE)
                || (!swipingRight && deltaX > -DISPLACE_CHOICE)) {
            ViewCompat.setTranslationX(frontView, deltaX);
        }
    } else {
        ViewCompat.setTranslationX(frontView, deltaX);
    }
}