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

The following are Jave code examples for showing how to use getAlpha() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: buildAPKsSamples   File: ShadowLayout.java   Source Code and License Vote up 7 votes
/**
 * Overriding onDraw allows us to draw shadows behind every child of this container.
 * onDraw() is called to draw a layout's content before the children are drawn, so the
 * shadows will be drawn first, behind the children (which is what we want).
 */
@Override
protected void onDraw(Canvas canvas) {
    for (int i = 0; i < getChildCount(); ++i) {
        View child = getChildAt(i);
        if (child.getVisibility() != View.VISIBLE || child.getAlpha() == 0) {
            continue;
        }
        int depthFactor = (int) (80 * mShadowDepth);
        canvas.save();
        canvas.translate(child.getLeft() + depthFactor,
                child.getTop() + depthFactor);
        canvas.concat(child.getMatrix());
        tempShadowRectF.right = child.getWidth();
        tempShadowRectF.bottom = child.getHeight();
        canvas.drawBitmap(mShadowBitmap, sShadowRect, tempShadowRectF, mShadowPaint);
        canvas.restore();
    }
}
 
Example 2
Project: GitHub   File: SimpleViewBehavior.java   Source Code and License Vote up 6 votes
/** 初始化数据 */
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 3
Project: LaunchEnr   File: WorkspaceStateTransitionAnimation.java   Source Code and License Vote up 6 votes
public static void updateVisibility(View view, boolean accessibilityEnabled) {
    // We want to avoid the extra layout pass by setting the views to GONE unless
    // accessibility is on, in which case not setting them to GONE causes a glitch.
    int invisibleState = accessibilityEnabled ? View.GONE : View.INVISIBLE;
    if (view.getAlpha() < ALPHA_CUTOFF_THRESHOLD && view.getVisibility() != invisibleState) {
        view.setVisibility(invisibleState);
    } else if (view.getAlpha() > ALPHA_CUTOFF_THRESHOLD
            && view.getVisibility() != View.VISIBLE) {
        view.setVisibility(View.VISIBLE);
    }
}
 
Example 4
Project: airgram   File: ViewProxy.java   Source Code and License Vote up 6 votes
public static float getAlpha(View view) {
    if (View10.NEED_PROXY) {
        return View10.wrap(view).getAlpha();
    } else {
        return view.getAlpha();
    }
}
 
Example 5
Project: Hotspot-master-devp   File: BitmapCommonUtils.java   Source Code and License Vote up 6 votes
public static Bitmap getViewBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

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

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

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(comBitmap.getLeft(), comBitmap.getTop(), comBitmap.getLeft()+width, comBitmap.getTop()+height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap);
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}
 
Example 6
Project: ucar-weex-core   File: WXSliderNeighbor.java   Source Code and License Vote up 6 votes
private void updateScaleAndAlpha(View view, float alpha, float scale) {
    if(null == view) {
        return;
    }
    if(alpha >= 0 && view.getAlpha() != alpha) {
        view.setAlpha(alpha);
    }
    if(scale >= 0 && view.getScaleX() != scale) {
        view.setScaleX(scale);
        view.setScaleY(scale);
    }
}
 
Example 7
Project: FireBaseTest   File: ViewUtils.java   Source Code and License Vote up 6 votes
/**
 * Starts a fade out animation on the view.
 */
public static void animateFadeOut(View view) {

    view.animate().cancel();

    if (view.getAlpha() != 0f || view.getVisibility() == View.VISIBLE) {
        view.setVisibility(View.VISIBLE);
        view.setAlpha(1f);
        view.animate().alpha(0f).start();
    } else {
        view.setAlpha(0f);
        view.setVisibility(View.INVISIBLE);
    }
}
 
Example 8
Project: boohee_v5.6   File: ViewPropertyAnimatorHC.java   Source Code and License Vote up 6 votes
private float getValue(int propertyConstant) {
    View v = (View) this.mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case 1:
                return v.getTranslationX();
            case 2:
                return v.getTranslationY();
            case 4:
                return v.getScaleX();
            case 8:
                return v.getScaleY();
            case 16:
                return v.getRotation();
            case 32:
                return v.getRotationX();
            case 64:
                return v.getRotationY();
            case 128:
                return v.getX();
            case 256:
                return v.getY();
            case 512:
                return v.getAlpha();
        }
    }
    return 0.0f;
}
 
Example 9
Project: chromium-for-android-56-debug-video   File: LocationBarLayout.java   Source Code and License Vote up 6 votes
private void changeLocationBarIcon() {
    if (mLocationBarIconActiveAnimator != null && mLocationBarIconActiveAnimator.isRunning()) {
        mLocationBarIconActiveAnimator.cancel();
    }

    mLocationBarButtonType = getLocationBarButtonToShow();

    View viewToBeShown = null;
    switch (mLocationBarButtonType) {
        case BUTTON_TYPE_SECURITY_ICON:
            viewToBeShown = mSecurityButton;
            mLocationBarIconActiveAnimator = mSecurityButtonShowAnimator;
            break;
        case BUTTON_TYPE_NAVIGATION_ICON:
            viewToBeShown = mNavigationButton;
            mLocationBarIconActiveAnimator = mNavigationIconShowAnimator;
            break;
        case BUTTON_TYPE_NONE:
        default:
            mLocationBarIconActiveAnimator = null;
            return;
    }

    if (viewToBeShown.getVisibility() == VISIBLE && viewToBeShown.getAlpha() == 1) {
        return;
    }
    if (shouldAnimateIconChanges()) {
        mLocationBarIconActiveAnimator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        mLocationBarIconActiveAnimator.setDuration(0);
    }
    mLocationBarIconActiveAnimator.start();
}
 
Example 10
Project: FloatingNew   File: FloatingActionMenu.java   Source Code and License Vote up 6 votes
public Item(View view, int width, int height) {
    this.view = view;
    this.width = width;
    this.height = height;
    alpha = view.getAlpha();
    x = 0;
    y = 0;
}
 
Example 11
Project: FlickLauncher   File: WorkspaceStateTransitionAnimation.java   Source Code and License Vote up 6 votes
public static void updateVisibility(View view, boolean accessibilityEnabled) {
    // We want to avoid the extra layout pass by setting the views to GONE unless
    // accessibility is on, in which case not setting them to GONE causes a glitch.
    int invisibleState = accessibilityEnabled ? View.GONE : View.INVISIBLE;
    if (view.getAlpha() < ALPHA_CUTOFF_THRESHOLD && view.getVisibility() != invisibleState) {
        view.setVisibility(invisibleState);
    } else if (view.getAlpha() > ALPHA_CUTOFF_THRESHOLD
            && view.getVisibility() != View.VISIBLE) {
        view.setVisibility(View.VISIBLE);
    }
}
 
Example 12
Project: AcademApp   File: MaterialIn.java   Source Code and License Vote up 6 votes
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 13
Project: morphos   File: ViewDefault.java   Source Code and License Vote up 6 votes
public void updateView(View v) {
    if (v != null) {
        this.alpha = v.getAlpha();
        this.x = v.getX();
        this.y = v.getY();
        this.z = atLeastLollipop ? v.getZ() : 0;
        this.width = v.getWidth();
        this.height = v.getHeight();
        this.expansionScaleX = v.getScaleX();
        this.expansionScaleY = v.getScaleY();
        this.dispositionAngle = v.getRotation();
        this.dispositionAngleX = v.getRotationX();
        this.dispositionAngleY = v.getRotationY();
    }
}
 
Example 14
Project: conductor-attacher   File: FadeChangeHandler2.java   Source Code and License Vote up 6 votes
@Override @NonNull
protected Animator getAnimator(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush) {
  AnimatorSet animator = new AnimatorSet();
  if (to != null) {
    float start = isPush ? 0 : to.getAlpha();
    animator.play(ObjectAnimator.ofFloat(to, View.ALPHA, start, 1));
  }

  if (from != null && !isPush) {
    animator.play(ObjectAnimator.ofFloat(from, View.ALPHA, 0));
  }

  return animator;
}
 
Example 15
Project: LuaViewPlayground   File: ViewHelper.java   Source Code and License Vote up 5 votes
static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 16
Project: RNLearn_Project1   File: OpacityAnimationPropertyUpdater.java   Source Code and License Vote up 5 votes
@Override
protected float getProperty(View view) {
  return view.getAlpha();
}
 
Example 17
Project: AnimationWrapLayout   File: AnimationWrapLayout.java   Source Code and License Vote up 5 votes
synchronized public boolean addViewWithAnimation(final View view, final int position) {
    if (mChildrenMeasure.hasPreLayoutView()) {
        return false;
    }
    mChildrenMeasure.addViewStart(view, position);
    SparseArray<Layout> layoutSet = mChildrenMeasure.measure().getLayoutSet();

    final float alpha = view.getAlpha();
    view.setAlpha(0.0f);
    requestLayout();

    int count = this.getChildCount();
    if (count == 0) {
        addView(view, position);
        addAnimation(view, alpha, new AnimationCallback() {
            @Override
            public void onEnd() {
                mChildrenMeasure.addedViewComplete();
            }
        });
        return true;
    }

    final List<View> animatedViewList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        final View child = this.getChildAt(i);
        if (!shouldLayout(child)) {
            continue;
        }
        final Layout layout = layoutSet.valueAt(i);
        if (layout == null) {
            continue;
        }
        boolean isAnimated = translateAnimation(child, layout.l, layout.t, new AnimationCallback() {
            @Override
            public void onEnd() {
                layout.applyTo(child);
                child.setAnimation(null);
                if (animatedViewList.contains(child)) {
                    animatedViewList.remove(child);
                }
                if (animatedViewList.isEmpty()) {
                    mChildrenMeasure.addedViewComplete();
                    addView(view, position);
                    addAnimation(view, alpha, new AnimationCallback() {
                        @Override
                        public void onEnd() {
                        }
                    });
                }
            }
        });
        if (isAnimated) {
            animatedViewList.add(child);
        }
    }
    return true;
}
 
Example 18
Project: diycode   File: Expectations.java   Source Code and License Vote up 5 votes
public static AlphaAnimExpectation sameAlphaAs(View otherView) {
    return new AlphaAnimExpectationValue(otherView.getAlpha());
}
 
Example 19
Project: letv   File: ViewCompatHC.java   Source Code and License Vote up 5 votes
public static float getAlpha(View view) {
    return view.getAlpha();
}
 
Example 20
Project: RNLearn_Project1   File: OpacityAnimationPropertyUpdater.java   Source Code and License Vote up 5 votes
@Override
protected float getProperty(View view) {
  return view.getAlpha();
}