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:com.commonsware.cwac.mediarouter.app.MediaRouteButton.java

private void setRemoteIndicatorDrawable(Drawable d) {
    if (mRemoteIndicator != null) {
        mRemoteIndicator.setCallback(null);
        unscheduleDrawable(mRemoteIndicator);
    }//  www  .  j ava  2s.co m
    mRemoteIndicator = d;
    if (d != null) {
        d.setCallback(this);
        d.setState(getDrawableState());
        d.setVisible(getVisibility() == VISIBLE, false);
    }

    refreshDrawableState();
}

From source file:android.support.v7.app.MediaRouteButton.java

/**
 * Sets a drawable to use as the remote route indicator.
 *///from   w w w. java 2  s .c o m
public void setRemoteIndicatorDrawable(Drawable d) {
    if (mRemoteIndicator != null) {
        mRemoteIndicator.setCallback(null);
        unscheduleDrawable(mRemoteIndicator);
    }
    mRemoteIndicator = d;
    if (d != null) {
        d.setCallback(this);
        d.setState(getDrawableState());
        d.setVisible(getVisibility() == VISIBLE, false);
    }

    refreshDrawableState();
}

From source file:com.guoxiaoxing.cloud.music.magicasakura.widgets.AppCompatImageHelper.java

private boolean applySupportImageTint() {
    Drawable image = ((ImageView) mView).getDrawable();
    AnimationDrawable animationDrawable = null;
    if (image instanceof AnimationDrawable) {
        Log.e("drawable", "is animationdrawable");
        animationDrawable = ((AnimationDrawable) image);
        //image = animationDrawable;
    }//from w w  w  .j a  v a 2  s  . c  o m

    if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) {

        if (animationDrawable != null) {
            Log.e("drawable", "is animationdrawable not null");
            Drawable tintDrawable = animationDrawable;
            Log.e("drawable", "start0");
            tintDrawable = DrawableCompat.wrap(tintDrawable);
            Log.e("drawable", "start1");
            if (mImageTintInfo.mHasTintList) {
                DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
            }
            if (mImageTintInfo.mHasTintMode) {
                DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
            }
            if (tintDrawable.isStateful()) {
                tintDrawable.setState(mView.getDrawableState());
            }
            tintDrawable = DrawableCompat.unwrap(tintDrawable);
            setImageDrawable(tintDrawable);
            if (image == tintDrawable) {
                Log.e("drawable", "invalidateself");
                // tintDrawable.invalidateSelf();
            }
            return true;
        } else {
            Drawable tintDrawable = image.mutate();
            tintDrawable = DrawableCompat.wrap(tintDrawable);
            if (mImageTintInfo.mHasTintList) {
                DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
            }
            if (mImageTintInfo.mHasTintMode) {
                DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
            }
            if (tintDrawable.isStateful()) {
                tintDrawable.setState(mView.getDrawableState());
            }
            setImageDrawable(tintDrawable);
            if (image == tintDrawable) {
                tintDrawable.invalidateSelf();
            }
            return true;
        }

    }
    return false;
}

From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundDrawableHelper.java

private Drawable applySupportCompoundDrawableTint(int position) {
    Drawable originDrawable = ((TextView) mView).getCompoundDrawables()[position];
    Drawable compoundDrawable = originDrawable;
    TintInfo tintInfo = mCompoundDrawableTintInfos[position];
    if (compoundDrawable != null && tintInfo != null && tintInfo.mHasTintList) {
        compoundDrawable = DrawableCompat.wrap(compoundDrawable);
        compoundDrawable.mutate();/*w  ww  . j  a  v a2 s. c  o  m*/
        if (tintInfo.mHasTintList) {
            DrawableCompat.setTintList(compoundDrawable, tintInfo.mTintList);
        }
        if (tintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(compoundDrawable, tintInfo.mTintMode);
        }
        if (compoundDrawable.isStateful()) {
            compoundDrawable.setState(originDrawable.getState());
        }
        return compoundDrawable;
    }
    return originDrawable;
}

From source file:com.money.manager.ex.adapter.CategoryExpandableListAdapter.java

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    CategoryListItemViewHolderGroup holder;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(mLayout, null);

        holder = new CategoryListItemViewHolderGroup(convertView);

        convertView.setTag(holder);//  ww w  .  j  a  v a2s  .  c o m
    } else {
        holder = (CategoryListItemViewHolderGroup) convertView.getTag();
    }

    // prevent exceptions. todo: Find out how this happens in the first place.
    if (mCategories.size() == 0)
        return convertView;

    Category category = mCategories.get(groupPosition);

    holder.text1.setText(category.getName());

    // Selector

    if (mShowSelector) {
        holder.selector.setVisibility(View.VISIBLE);
        // set the tag to be the group position
        holder.selector.setTag(category.getId());

        holder.selector.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String tag = v.getTag().toString();
                Integer groupId = Integer.parseInt(tag);
                setIdGroupChecked(groupId);
                // close
                closeFragment();
            }
        });
    } else {
        holder.selector.setVisibility(View.GONE);
    }

    if (holder.collapseImageView != null) {
        TypedArray expandableListViewStyle = getContext().getTheme()
                .obtainStyledAttributes(new int[] { android.R.attr.expandableListViewStyle });
        TypedArray groupIndicator = getContext().getTheme().obtainStyledAttributes(
                expandableListViewStyle.getResourceId(0, 0), new int[] { android.R.attr.groupIndicator });
        Drawable drawable = groupIndicator.getDrawable(0);
        holder.collapseImageView.setImageDrawable(drawable);
        expandableListViewStyle.recycle();
        groupIndicator.recycle();

        boolean hasChildren = getChildrenCount(groupPosition) != 0;
        if (!hasChildren) {
            holder.collapseImageView.setVisibility(View.INVISIBLE);
        } else {
            holder.collapseImageView.setVisibility(View.VISIBLE);

            if (drawable != null) {
                drawable.setState(isExpanded ? expandedStateSet : emptyStateSet);
            }
        }
    }

    return convertView;
}

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

void applyButtonTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView);

    if (buttonDrawable != null && (mHasButtonTint || mHasButtonTintMode)) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mHasButtonTint) {
            DrawableCompat.setTintList(buttonDrawable, mButtonTintList);
        }/*  www  .j  av a  2  s  .c o m*/
        if (mHasButtonTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mButtonTintMode);
        }
        // The drawable (or one of its children) may not have been
        // stateful before applying the tint, so let's try again.
        if (buttonDrawable.isStateful()) {
            buttonDrawable.setState(mView.getDrawableState());
        }
        mView.setButtonDrawable(buttonDrawable);
    }
}

From source file:com.bilibili.magicasakura.widgets.AppCompatForegroundHelper.java

private boolean applySupportForegroundTint() {
    Drawable foregroundDrawable = getForeground();
    if (foregroundDrawable != null && mForegroundTintInfo != null && mForegroundTintInfo.mHasTintList) {
        foregroundDrawable = DrawableCompat.wrap(foregroundDrawable);
        foregroundDrawable = foregroundDrawable.mutate();
        if (mForegroundTintInfo.mHasTintList) {
            DrawableCompat.setTintList(foregroundDrawable, mForegroundTintInfo.mTintList);
        }//www.  j  a va2  s .c  om
        if (mForegroundTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(foregroundDrawable, mForegroundTintInfo.mTintMode);
        }
        if (foregroundDrawable.isStateful()) {
            foregroundDrawable.setState(mView.getDrawableState());
        }
        setForegroundDrawable(foregroundDrawable);
        return true;
    }
    return false;
}

From source file:com.bilibili.magicasakura.widgets.AppCompatBackgroundHelper.java

private boolean applySupportBackgroundTint() {
    Drawable backgroundDrawable = mView.getBackground();
    if (backgroundDrawable != null && mBackgroundTintInfo != null && mBackgroundTintInfo.mHasTintList) {
        backgroundDrawable = DrawableCompat.wrap(backgroundDrawable);
        backgroundDrawable = backgroundDrawable.mutate();
        if (mBackgroundTintInfo.mHasTintList) {
            DrawableCompat.setTintList(backgroundDrawable, mBackgroundTintInfo.mTintList);
        }//  w  w w .  j  a  v  a 2  s .  co  m
        if (mBackgroundTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(backgroundDrawable, mBackgroundTintInfo.mTintMode);
        }
        if (backgroundDrawable.isStateful()) {
            backgroundDrawable.setState(mView.getDrawableState());
        }
        setBackgroundDrawable(backgroundDrawable);
        return true;
    }
    return false;
}

From source file:com.shizhefei.view.largeimage.LargeImageView.java

private void updateDrawable(Drawable d) {
    if (mDrawable != null) {
        mDrawable.setCallback(null);//from w  w w  .  j  av  a2  s .c om
        unscheduleDrawable(mDrawable);
    }
    mDrawable = d;
    if (d != null) {
        d.setCallback(this);
        DrawableCompat.setLayoutDirection(d, DrawableCompat.getLayoutDirection(d));
        if (d.isStateful()) {
            d.setState(getDrawableState());
        }
        d.setVisible(getVisibility() == VISIBLE, true);
        d.setLevel(mLevel);
        mDrawableWidth = d.getIntrinsicWidth();
        mDrawableHeight = d.getIntrinsicHeight();
    } else {
        mDrawableWidth = mDrawableHeight = -1;
    }
}

From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundButtonHelper.java

public boolean applySupportButtonDrawableTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) mView);
    if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mCompoundButtonTintInfo.mHasTintList) {
            DrawableCompat.setTintList(buttonDrawable, mCompoundButtonTintInfo.mTintList);
        }//from w w w .j  a  v  a  2  s.c o m
        if (mCompoundButtonTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mCompoundButtonTintInfo.mTintMode);
        }
        // The drawable (or one of its children) may not have been
        // stateful before applying the tint, so let's try again.
        if (buttonDrawable.isStateful()) {
            buttonDrawable.setState(mView.getDrawableState());
        }
        setButtonDrawable(buttonDrawable);
        return true;
    }
    return false;
}