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

The following examples show how to use android.view.View#getAlpha() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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 Project: sa-sdk-android   File: ViewUtil.java    License: 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 3
Source Project: scene   File: AnimatorUtility.java    License: 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 4
Source Project: DevUtils   File: ViewUtils.java    License: 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 5
Source Project: Mover   File: ViewPropertyAnimatorHC.java    License: 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 6
Source Project: Material-In   File: MaterialIn.java    License: 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 7
/**
 * 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 8
Source Project: okhttp-OkGo   File: SimpleViewBehavior.java    License: 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 9
Source Project: floatingMenu   File: SubButton.java    License: 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 10
Source Project: LB-Launcher   File: DragController.java    License: 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 11
Source Project: Auie   File: UEViewHelper.java    License: GNU General Public License v2.0 4 votes vote down vote up
static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 12
Source Project: CircularReveal   File: DynamicAnimation.java    License: MIT License 4 votes vote down vote up
@Override
public float getValue(View view) {
  return view.getAlpha();
}
 
Example 13
Source Project: android-test   File: ViewMatchers.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  return view.getAlpha() == alpha;
}
 
Example 14
Source Project: imsdk-android   File: ViewHelper.java    License: MIT License 4 votes vote down vote up
static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 15
Source Project: weex   File: ViewUtil.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public float getAlpha(View view) {
  return view.getAlpha();
}
 
Example 16
Source Project: guideshow   File: ViewCompatHC.java    License: MIT License 4 votes vote down vote up
public static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 17
Source Project: litho   File: MountState.java    License: 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 18
Source Project: UltimateAndroid   File: ViewHelper.java    License: Apache License 2.0 4 votes vote down vote up
static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 19
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 20
public float getTransitionAlpha(@NonNull View v) {
    return v.getAlpha();
}