Example usage for android.graphics.drawable Drawable setVisible

List of usage examples for android.graphics.drawable Drawable setVisible

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setVisible.

Prototype

public boolean setVisible(boolean visible, boolean restart) 

Source Link

Document

Set whether this Drawable is visible.

Usage

From source file:com.facebook.litho.ComponentHost.java

@Override
public void setVisibility(int visibility) {
    super.setVisibility(visibility);

    for (int i = 0, size = mDrawableMountItems.size(); i < size; i++) {
        final Drawable drawable = (Drawable) mDrawableMountItems.valueAt(i).getContent();
        drawable.setVisible(visibility == View.VISIBLE, false);
    }/*from   w  w w  . j a  v  a  2  s  .c  o  m*/
}

From source file:androidx.mediarouter.app.MediaRouteButton.java

/**
 * Sets a drawable to use as the remote route indicator.
 *///from w  w  w  .  j a v a2 s  .c  o  m
public void setRemoteIndicatorDrawable(Drawable d) {
    if (mRemoteIndicatorLoader != null) {
        mRemoteIndicatorLoader.cancel(false);
    }

    if (mRemoteIndicator != null) {
        mRemoteIndicator.setCallback(null);
        unscheduleDrawable(mRemoteIndicator);
    }
    if (d != null) {
        if (mButtonTint != null) {
            d = DrawableCompat.wrap(d.mutate());
            DrawableCompat.setTintList(d, mButtonTint);
        }
        d.setCallback(this);
        d.setState(getDrawableState());
        d.setVisible(getVisibility() == VISIBLE, false);
    }
    mRemoteIndicator = d;

    refreshDrawableState();
    if (mAttachedToWindow && mRemoteIndicator != null
            && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) {
        AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent();
        if (mIsConnecting) {
            if (!curDrawable.isRunning()) {
                curDrawable.start();
            }
        } else if (mRemoteActive) {
            if (curDrawable.isRunning()) {
                curDrawable.stop();
            }
            curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1);
        }
    }
}

From source file:android.support.v7.widget.SuggestionsAdapter.java

/**
 * Sets the drawable in an image view, makes sure the view is only visible if there
 * is a drawable./*from   w w  w . ja v  a  2 s  .  c  om*/
 */
private void setViewDrawable(ImageView v, Drawable drawable, int nullVisibility) {
    // Set the icon even if the drawable is null, since we need to clear any
    // previous icon.
    v.setImageDrawable(drawable);

    if (drawable == null) {
        v.setVisibility(nullVisibility);
    } else {
        v.setVisibility(View.VISIBLE);

        // This is a hack to get any animated drawables (like a 'working' spinner)
        // to animate. You have to setVisible true on an AnimationDrawable to get
        // it to start animating, but it must first have been false or else the
        // call to setVisible will be ineffective. We need to clear up the story
        // about animated drawables in the future, see http://b/1878430.
        drawable.setVisible(false, false);
        drawable.setVisible(true, false);
    }
}

From source file:com.tandong.sa.sherlock.widget.SuggestionsAdapter.java

/**
 * Sets the drawable in an image view, makes sure the view is only visible
 * if there is a drawable.//w ww  .j  a  va 2  s . co m
 */
private void setViewDrawable(ImageView v, Drawable drawable, int nullVisibility) {
    // Set the icon even if the drawable is null, since we need to clear any
    // previous icon.
    v.setImageDrawable(drawable);

    if (drawable == null) {
        v.setVisibility(nullVisibility);
    } else {
        v.setVisibility(View.VISIBLE);

        // This is a hack to get any animated drawables (like a 'working'
        // spinner)
        // to animate. You have to setVisible true on an AnimationDrawable
        // to get
        // it to start animating, but it must first have been false or else
        // the
        // call to setVisible will be ineffective. We need to clear up the
        // story
        // about animated drawables in the future, see http://b/1878430.
        drawable.setVisible(false, false);
        drawable.setVisible(true, false);
    }
}

From source file:com.hippo.widget.recyclerview.EasyRecyclerView.java

private void positionSelector(int position, View sel, boolean manageHotspot, float x, float y) {
    final boolean positionChanged = position != mSelectorPosition;
    if (position != INVALID_POSITION) {
        mSelectorPosition = position;/*w ww  . jav  a 2  s .  c  o  m*/
    }

    final Rect selectorRect = mSelectorRect;
    selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom());

    // Adjust for selection padding.
    selectorRect.left -= mSelectionLeftPadding;
    selectorRect.top -= mSelectionTopPadding;
    selectorRect.right += mSelectionRightPadding;
    selectorRect.bottom += mSelectionBottomPadding;

    // Update the selector drawable.
    final Drawable selector = mSelector;
    if (selector != null) {
        if (positionChanged) {
            // Wipe out the current selector state so that we can start
            // over in the new position with a fresh state.
            selector.setVisible(false, false);
            selector.setState(StateSet.NOTHING);
        }
        selector.setBounds(selectorRect);
        if (positionChanged) {
            if (getVisibility() == VISIBLE) {
                selector.setVisible(true, false);
            }
            updateSelectorState();
        }
        if (manageHotspot) {
            DrawableUtils.setHotspot(selector, x, y);
        }
    }
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Updates current indicator to the specified one. If this seek bar has discrete mode enabled
 * ({@link #isDiscrete()}), the given indicator will be updated to scaleable drawable if it is
 * not yet.//from w w w  .j  av a 2 s  .c o  m
 *
 * @param indicator The new indicator to update to.
 */
private void updateDiscreteIndicator(Drawable indicator) {
    if (mDecorator.hasPrivateFlag(PFLAG_DISCRETE)) {
        indicator = mAnimations.makeDiscreteIndicatorScaleable(indicator,
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
    }
    if (mDiscreteIndicator != indicator) {
        final boolean needUpdate;
        if (mDiscreteIndicator != null) {
            mDiscreteIndicator.setCallback(null);
            unscheduleDrawable(mDiscreteIndicator);
            needUpdate = true;
        } else {
            needUpdate = false;
        }
        if (indicator != null) {
            indicator.setCallback(this);
            indicator.setVisible(getVisibility() == VISIBLE, false);

            if (indicator.getIntrinsicWidth() != mDiscreteIndicatorWidth
                    || indicator.getIntrinsicHeight() != mDiscreteIndicatorHeight) {
                this.mDiscreteIndicatorWidth = indicator.getIntrinsicWidth();
                this.mDiscreteIndicatorHeight = indicator.getIntrinsicHeight();
                requestLayout();
            }
        } else {
            this.mDiscreteIndicatorRes = 0;
            this.mDiscreteIndicatorWidth = mDiscreteIndicatorHeight = 0;
            requestLayout();
        }
        this.mDiscreteIndicator = indicator;
        this.applyDiscreteIndicatorTint();
        if (needUpdate) {
            this.updateDiscreteIndicatorPosition(getWidth(), getHeight());
            if (mDiscreteIndicator.isStateful()) {
                mDiscreteIndicator.setState(getDrawableState());
            }
            this.invalidateDiscreteIndicatorArea();
        }
    }
}