Example usage for android.graphics.drawable Drawable setState

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

Introduction

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

Prototype

public boolean setState(@NonNull final int[] stateSet) 

Source Link

Document

Specify a set of states for the drawable.

Usage

From source file:am.widget.basetabstrip.BaseTabStrip.java

/**
 * ?/*from  w  ww . ja va 2 s .c  o m*/
 */
protected void createItemBackgrounds() {
    if (!hasItemBackgrounds())
        return;
    int count = getItemCount();
    if (count > 0) {
        for (int i = 0; i < count; i++) {
            if (i < mTabItemBackgrounds.size()) {
                mTabItemBackgrounds.get(i).setState(onCreateDrawableState(0));
            } else {
                Drawable tag = mTabItemBackground.getConstantState().newDrawable();
                tag.setCallback(this);
                mTabItemBackgrounds.add(tag);
            }
        }
    } else {
        for (Drawable drawable : mTabItemBackgrounds) {
            drawable.setState(onCreateDrawableState(0));
        }
    }
}

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 a 2s  .  com*/
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:am.widget.basetabstrip.BaseTabStripGroup.java

/**
 * ?/*from w  w w  . j  a  v a2s . c o  m*/
 */
protected void createItemBackgrounds() {
    if (!hasItemBackgrounds())
        return;
    int count = getItemCount();
    if (count > 0) {
        for (int i = 0; i < count; i++) {
            if (i < mTabItemBackgrounds.size()) {
                mTabItemBackgrounds.get(i).setState(onCreateDrawableState(0));
            } else {
                Drawable tag;
                if (mTabItemBackground.getConstantState() != null) {
                    tag = mTabItemBackground.getConstantState().newDrawable().mutate();
                } else {
                    tag = mTabItemBackground.mutate();
                }
                tag.setCallback(this);
                mTabItemBackgrounds.add(tag);
            }
        }
    } else {
        for (Drawable drawable : mTabItemBackgrounds) {
            drawable.setState(onCreateDrawableState(0));
        }
    }
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.StageView.java

private void updateSelectorState() {
    for (int i = 0; i < mSelectors.size(); i++) {
        Drawable d = mSelectors.valueAt(i);
        if (d != null) {
            if (shouldShowSelector()) {
                d.setState(getDrawableState());
            } else {
                d.setState(StateSet.NOTHING);
            }/* w ww  .ja v  a  2s  .  co m*/
        }
    }
}

From source file:android.support.designox.widget.CollapsingToolbarLayout.java

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    final int[] state = getDrawableState();
    boolean changed = false;

    Drawable d = mStatusBarScrim;
    if (d != null && d.isStateful()) {
        changed |= d.setState(state);
    }/*w ww .j a  va 2 s  .  c o  m*/
    d = mContentScrim;
    if (d != null && d.isStateful()) {
        changed |= d.setState(state);
    }

    if (changed) {
        invalidate();
    }
}

From source file:am.widget.basetabstrip.BaseTabStrip.java

@Override
protected void drawableStateChanged() {
    final float downMotionX = tabStripGestureDetector.getDownMotionX();
    final float downMotionY = tabStripGestureDetector.getDownMotionY();
    int position = pointToPosition(downMotionX, downMotionY);
    if (position >= 0 && position < mTabItemBackgrounds.size()) {
        Drawable tag = mTabItemBackgrounds.get(position);
        DrawableCompat.setHotspot(tag, getHotspotX(tag, position, downMotionX, downMotionY),
                getHotspotY(tag, position, downMotionX, downMotionY));
        if (tag.isStateful()) {
            tag.setState(getDrawableState());
        }//ww  w.  java  2  s  . c  o  m
    }
    super.drawableStateChanged();
}

From source file:android.support.design.widget.CollapsingToolbarLayout.java

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();

    final int[] state = getDrawableState();
    boolean changed = false;

    Drawable d = mStatusBarScrim;
    if (d != null && d.isStateful()) {
        changed |= d.setState(state);
    }//from  w w w  . jav a 2s.  c om
    d = mContentScrim;
    if (d != null && d.isStateful()) {
        changed |= d.setState(state);
    }
    if (mCollapsingTextHelper != null) {
        changed |= mCollapsingTextHelper.setState(state);
    }

    if (changed) {
        invalidate();
    }
}

From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    final Drawable d = mShadowDrawable;
    if (d != null && d.isStateful()) {
        d.setState(getDrawableState());
    }/*from w  w  w.ja  v a 2  s.  c o m*/
}

From source file:org.kde.necessitas.ministro.ExtractStyle.java

Object getStateListDrawable_old(Drawable drawable, String filename) {
    JSONObject json = new JSONObject();
    ArrayList<Integer> drawableList = new ArrayList<Integer>();
    drawable.setState(EMPTY_STATE_SET);
    try {/*  ww w .j  ava2 s  .c om*/
        json.put("empty", getDrawable(drawable.getCurrent(), filename));
        drawableList.add(drawable.getCurrent().hashCode());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    for (int c = 1; c <= DrawableStates.length; c++)
        for (int u = 0; u < 1 << DrawableStates.length; u++)
            if (bitCount(u) == c)
                addSolution(filename, json, c, drawable, drawableList, u);
    return json;
}

From source file:org.kde.necessitas.ministro.ExtractStyle.java

void addSolution(String filename, JSONObject json, int c, Drawable drawable, ArrayList<Integer> drawableList,
        int u) {//from   w  ww. ja v  a2  s.c o m
    int pos = 0;
    int states[] = new int[c];
    String[] statesText = new String[c];

    for (int n = 0; u > 0; ++n, u >>= 1)
        if ((u & 1) > 0) {
            statesText[pos] = DrawableStatesLabels[n];
            states[pos++] = DrawableStates[n];
        }
    drawable.setState(states);
    addDrawableItemIfNotExists(json, drawableList, drawable.getCurrent(), statesText, filename);
}