Java Code Examples for android.view.View#getAlpha()

The following examples show how to use android.view.View#getAlpha() . 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: ViewAccessibilityUtils.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the supplied {@link View} is visible to the user, which requires that it be
 * marked visible, that all its parents are visible, that it and all parents have alpha greater
 * than 0, and that it has non-zero size. This code attempts to replicate the protected method
 * {@code View.isVisibleToUser}.
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if {@code view} is visible to the user
 */
@RequiresApi(Build.VERSION_CODES.HONEYCOMB) // Uses View#getAlpha
public static boolean isVisibleToUser(View view) {
  if (view == null) {
    return false;
  }

  Object current = view;
  while (current instanceof View) {
    View currentView = (View) current;
    if ((currentView.getAlpha() <= 0) || (currentView.getVisibility() != View.VISIBLE)) {
      return false;
    }
    current = currentView.getParent();
  }
  return view.getGlobalVisibleRect(new Rect());
}
 
Example 2
Source File: AnimatorUtility.java    From scene with Apache License 2.0 5 votes vote down vote up
@NonNull
public static AnimatorInfo captureViewStatus(@NonNull View view) {
    return new AnimatorInfo(view.getTranslationX(),
            view.getTranslationY(),
            view.getScaleX(),
            view.getScaleY(),
            view.getRotation(),
            view.getRotationX(),
            view.getRotationY(),
            view.getAlpha());
}
 
Example 3
Source File: DragController.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/**
 * Draw the view into a bitmap.
 */
Bitmap getViewBitmap(View v) {
    v.clearFocus();
    v.setPressed(false);

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

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

    if (color != 0) {
        v.destroyDrawingCache();
    }
    v.buildDrawingCache();
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }

    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

    // Restore the view
    v.destroyDrawingCache();
    v.setAlpha(alpha);
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);

    return bitmap;
}
 
Example 4
Source File: SubButton.java    From floatingMenu with Apache License 2.0 5 votes vote down vote up
public SubButton(View view, int width, int height) {
    this.view = view;
    this.width = width;
    this.height = height;
    this.alpha = view.getAlpha();
    this.x = 0;
    this.y = 0;
}
 
Example 5
Source File: SimpleViewBehavior.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
/** 初始化数据 */
private void prepare(CoordinatorLayout parent, View child, View dependency) {
    mDependStartX = (int) dependency.getX();
    mDependStartY = (int) dependency.getY();
    mDependStartWidth = dependency.getWidth();
    mDependStartHeight = dependency.getHeight();
    mStartX = (int) child.getX();
    mStartY = (int) child.getY();
    mStartWidth = child.getWidth();
    mStartHeight = child.getHeight();
    mStartAlpha = child.getAlpha();
    mStartRotateX = child.getRotationX();
    mStartRotateY = child.getRotationY();

    //特殊处理y方向变化
    if (mDependTargetY == UNSPECIFIED_INT && dependency instanceof AppBarLayout) {
        mDependTargetY = ((AppBarLayout) dependency).getTotalScrollRange();
    }
    // 背景颜色渐变
    if (child.getBackground() instanceof ColorDrawable) mStartBackgroundColor = ((ColorDrawable) child.getBackground()).getColor();
    // 自定义动画
    if (mAnimationId != 0) {
        mAnimation = AnimationUtils.loadAnimation(child.getContext(), mAnimationId);
        mAnimation.initialize(child.getWidth(), child.getHeight(), parent.getWidth(), parent.getHeight());
    }
    // 兼容5.0以上的沉浸模式
    if (Build.VERSION.SDK_INT > 16 && parent.getFitsSystemWindows() && targetY != UNSPECIFIED_INT) {
        targetY += getStatusBarHeight(parent.getContext());
    }
    isPrepared = true;
}
 
Example 6
Source File: ViewPropertyAnimatorHC.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets the value of the named property from the View object.
 *
 * @param propertyConstant The property whose value should be returned
 * @return float The value of the named property
 */
private float getValue(int propertyConstant) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //return info.mTranslationX;
                return v.getTranslationX();
            case TRANSLATION_Y:
                //return info.mTranslationY;
                return v.getTranslationY();
            case ROTATION:
                //return info.mRotation;
                return v.getRotation();
            case ROTATION_X:
                //return info.mRotationX;
                return v.getRotationX();
            case ROTATION_Y:
                //return info.mRotationY;
                return v.getRotationY();
            case SCALE_X:
                //return info.mScaleX;
                return v.getScaleX();
            case SCALE_Y:
                //return info.mScaleY;
                return v.getScaleY();
            case X:
                //return v.mLeft + info.mTranslationX;
                return v.getX();
            case Y:
                //return v.mTop + info.mTranslationY;
                return v.getY();
            case ALPHA:
                //return info.mAlpha;
                return v.getAlpha();
        }
    }
    return 0;
}
 
Example 7
Source File: MaterialIn.java    From Material-In with Apache License 2.0 5 votes vote down vote up
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
    if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
        view.clearAnimation();
        view.animate().cancel();
        final Resources res = view.getResources();
        final float endAlpha = view.getAlpha();
        final float endTranslateX = view.getTranslationX();
        final float endTranslateY = view.getTranslationY();
        view.setAlpha(0);
        final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
        fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
        fade.setInterpolator(new AccelerateInterpolator());
        fade.setStartDelay(delay);
        fade.start();
        ViewPropertyAnimator slide = view.animate();
        if (startOffsetY != 0) {
            view.setTranslationY(startOffsetY);
            slide.translationY(endTranslateY);
        } else {
            view.setTranslationX(startOffsetX);
            slide.translationX(endTranslateX);
        }
        slide.setInterpolator(new DecelerateInterpolator(2));
        slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
        slide.setStartDelay(delay);
        slide.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                if (fade.isStarted()) {
                    fade.cancel();
                }
                view.setAlpha(endAlpha);
                view.setTranslationX(endTranslateX);
                view.setTranslationY(endTranslateY);
            }
        });
        slide.start();
    }
}
 
Example 8
Source File: ViewPropertyAnimatorHC.java    From Mover with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets the value of the named property from the View object.
 *
 * @param propertyConstant The property whose value should be returned
 * @return float The value of the named property
 */
private float getValue(int propertyConstant) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //return info.mTranslationX;
                return v.getTranslationX();
            case TRANSLATION_Y:
                //return info.mTranslationY;
                return v.getTranslationY();
            case ROTATION:
                //return info.mRotation;
                return v.getRotation();
            case ROTATION_X:
                //return info.mRotationX;
                return v.getRotationX();
            case ROTATION_Y:
                //return info.mRotationY;
                return v.getRotationY();
            case SCALE_X:
                //return info.mScaleX;
                return v.getScaleX();
            case SCALE_Y:
                //return info.mScaleY;
                return v.getScaleY();
            case X:
                //return v.mLeft + info.mTranslationX;
                return v.getX();
            case Y:
                //return v.mTop + info.mTranslationY;
                return v.getY();
            case ALPHA:
                //return info.mAlpha;
                return v.getAlpha();
        }
    }
    return 0;
}
 
Example 9
Source File: ViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 View 透明度
 * @param view View
 * @return 透明度
 */
public static float getAlpha(final View view) {
    if (view != null) {
        return view.getAlpha();
    }
    return 1.0f;
}
 
Example 10
Source File: ViewUtil.java    From sa-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * View 自身是否可见
 *
 * @return View 宽、高、透明度 有一个 < 0 时,或 getLocalVisibleRect 为 false 时;返回 false 。
 * View getVisibility 不可见,且有 Animation getFillAfter 为  false 时;返回 false 。
 * View 无 Animation 时 getVisibility 不可见时返回 false 。
 */
@RequiresApi(api = 11)
public static boolean isViewSelfVisible(View view) {
    if (view == null) {
        return false;
    }
    if (view.getWidth() <= 0 || view.getHeight() <= 0 || view.getAlpha() <= 0.0f || !view.getLocalVisibleRect(new Rect())) {
        return false;
    }
    return (view.getVisibility() != VISIBLE && view.getAnimation() != null && view.getAnimation().getFillAfter()) || view.getVisibility() == VISIBLE;
}
 
Example 11
Source File: ViewUtil.java    From weex with Apache License 2.0 4 votes vote down vote up
@Override
public float getAlpha(View view) {
  return view.getAlpha();
}
 
Example 12
Source File: ViewCompatHC.java    From guideshow with MIT License 4 votes vote down vote up
public static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 13
Source File: MountState.java    From litho with Apache License 2.0 4 votes vote down vote up
private static void unsetAlpha(View view, NodeInfo nodeInfo) {
  if (nodeInfo.isAlphaSet() && view.getAlpha() != 1) {
    view.setAlpha(1);
  }
}
 
Example 14
Source File: ViewHelper.java    From imsdk-android with MIT License 4 votes vote down vote up
static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 15
Source File: ViewHelper.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 16
Source File: ViewMatchers.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  return view.getAlpha() == alpha;
}
 
Example 17
Source File: DynamicAnimation.java    From CircularReveal with MIT License 4 votes vote down vote up
@Override
public float getValue(View view) {
  return view.getAlpha();
}
 
Example 18
Source File: MediaActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void updateSections(RecyclerView listView, boolean checkTopBottom) {
    int count = listView.getChildCount();
    int minPositionDateHolder = Integer.MAX_VALUE;
    View minDateChild = null;
    float padding = listView.getPaddingTop() + actionBar.getTranslationY();
    int minTop = Integer.MAX_VALUE;
    int maxBottom = 0;

    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        int bottom = view.getBottom();
        minTop = Math.min(minTop, view.getTop());
        maxBottom = Math.max(bottom, maxBottom);
        if (bottom <= padding) {
            continue;
        }
        int position = view.getBottom();
        if (view instanceof SharedMediaSectionCell || view instanceof GraySectionCell) {
            if (view.getAlpha() != 1.0f) {
                view.setAlpha(1.0f);
            }
            if (position < minPositionDateHolder) {
                minPositionDateHolder = position;
                minDateChild = view;
            }
        }
    }
    if (minDateChild != null) {
        if (minDateChild.getTop() > padding) {
            if (minDateChild.getAlpha() != 1.0f) {
                minDateChild.setAlpha(1.0f);
            }
        } else {
            if (minDateChild.getAlpha() != 0.0f) {
                minDateChild.setAlpha(0.0f);
            }
        }
    }
    if (checkTopBottom) {
        if (maxBottom != 0 && maxBottom < (listView.getMeasuredHeight() - listView.getPaddingBottom())) {
            resetScroll();
        } else if (minTop != Integer.MAX_VALUE && minTop > listView.getPaddingTop() + actionBar.getTranslationY()) {
            scrollWithoutActionBar(listView, -listView.computeVerticalScrollOffset());
            resetScroll();
        }
    }
}
 
Example 19
Source File: UEViewHelper.java    From Auie with GNU General Public License v2.0 4 votes vote down vote up
static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 20
Source File: ViewUtils.java    From Transitions-Everywhere with Apache License 2.0 4 votes vote down vote up
public float getTransitionAlpha(@NonNull View v) {
    return v.getAlpha();
}