Java 类android.support.v4.widget.CompoundButtonCompat 实例源码

项目:boohee_v5.6    文件:AppCompatCompoundButtonHelper.java   
void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = this.mView.getContext().obtainStyledAttributes(attrs, R.styleable.CompoundButton, defStyleAttr, 0);
    try {
        if (a.hasValue(R.styleable.CompoundButton_android_button)) {
            int resourceId = a.getResourceId(R.styleable.CompoundButton_android_button, 0);
            if (resourceId != 0) {
                this.mView.setButtonDrawable(this.mDrawableManager.getDrawable(this.mView.getContext(), resourceId));
            }
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
            CompoundButtonCompat.setButtonTintList(this.mView, a.getColorStateList(R.styleable.CompoundButton_buttonTint));
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTintMode)) {
            CompoundButtonCompat.setButtonTintMode(this.mView, DrawableUtils.parseTintMode(a.getInt(R.styleable.CompoundButton_buttonTintMode, -1), null));
        }
        a.recycle();
    } catch (Throwable th) {
        a.recycle();
    }
}
项目:boohee_v5.6    文件:AppCompatCompoundButtonHelper.java   
void applyButtonTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(this.mView);
    if (buttonDrawable == null) {
        return;
    }
    if (this.mHasButtonTint || this.mHasButtonTintMode) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable).mutate();
        if (this.mHasButtonTint) {
            DrawableCompat.setTintList(buttonDrawable, this.mButtonTintList);
        }
        if (this.mHasButtonTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, this.mButtonTintMode);
        }
        if (buttonDrawable.isStateful()) {
            buttonDrawable.setState(this.mView.getDrawableState());
        }
        this.mView.setButtonDrawable(buttonDrawable);
    }
}
项目:MagicaSakura    文件:AppCompatCompoundButtonHelper.java   
public boolean applySupportButtonDrawableTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView);
    if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mCompoundButtonTintInfo.mHasTintList) {
            DrawableCompat.setTintList(buttonDrawable, mCompoundButtonTintInfo.mTintList);
        }
        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;
}
项目:FMTech    文件:AppCompatCompoundButtonHelper.java   
private void applyButtonTint()
{
  Drawable localDrawable1 = CompoundButtonCompat.getButtonDrawable(this.mView);
  if ((localDrawable1 != null) && ((this.mHasButtonTint) || (this.mHasButtonTintMode)))
  {
    Drawable localDrawable2 = DrawableCompat.wrap(localDrawable1).mutate();
    if (this.mHasButtonTint) {
      DrawableCompat.setTintList(localDrawable2, this.mButtonTintList);
    }
    if (this.mHasButtonTintMode) {
      DrawableCompat.setTintMode(localDrawable2, this.mButtonTintMode);
    }
    if (localDrawable2.isStateful()) {
      localDrawable2.setState(this.mView.getDrawableState());
    }
    this.mView.setButtonDrawable(localDrawable2);
  }
}
项目:FMTech    文件:AppCompatCompoundButtonHelper.java   
final void loadFromAttributes(AttributeSet paramAttributeSet, int paramInt)
{
  TypedArray localTypedArray = this.mView.getContext().obtainStyledAttributes(paramAttributeSet, R.styleable.CompoundButton, paramInt, 0);
  try
  {
    if (localTypedArray.hasValue(R.styleable.CompoundButton_android_button))
    {
      int i = localTypedArray.getResourceId(R.styleable.CompoundButton_android_button, 0);
      if (i != 0) {
        this.mView.setButtonDrawable(this.mTintManager.getDrawable(i, false));
      }
    }
    if (localTypedArray.hasValue(R.styleable.CompoundButton_buttonTint)) {
      CompoundButtonCompat.setButtonTintList(this.mView, localTypedArray.getColorStateList(R.styleable.CompoundButton_buttonTint));
    }
    if (localTypedArray.hasValue(R.styleable.CompoundButton_buttonTintMode)) {
      CompoundButtonCompat.setButtonTintMode(this.mView, DrawableUtils.parseTintMode$49602678(localTypedArray.getInt(R.styleable.CompoundButton_buttonTintMode, -1)));
    }
    return;
  }
  finally
  {
    localTypedArray.recycle();
  }
}
项目:MyCTFWriteUps    文件:AppCompatCompoundButtonHelper.java   
void applyButtonTint()
{
    Drawable drawable = CompoundButtonCompat.getButtonDrawable(mView);
    if (drawable != null && (mHasButtonTint || mHasButtonTintMode))
    {
        drawable = DrawableCompat.wrap(drawable).mutate();
        if (mHasButtonTint)
        {
            DrawableCompat.setTintList(drawable, mButtonTintList);
        }
        if (mHasButtonTintMode)
        {
            DrawableCompat.setTintMode(drawable, mButtonTintMode);
        }
        if (drawable.isStateful())
        {
            drawable.setState(mView.getDrawableState());
        }
        mView.setButtonDrawable(drawable);
    }
}
项目:Watermark    文件:MediaPageFragment.java   
@Override
public void setTheme() {
    super.setTheme();
    int checkTint = ThemeUtils.resolveColor(getContext(), R.attr.gallery_checkbox_button_tint_color, R.color.gallery_default_checkbox_button_tint_color);
    CompoundButtonCompat.setButtonTintList(mCbCheck, ColorStateList.valueOf(checkTint));
    int cbTextColor = ThemeUtils.resolveColor(getContext(), R.attr.gallery_checkbox_text_color, R.color.gallery_default_checkbox_text_color);
    mCbCheck.setTextColor(cbTextColor);

    int pageColor = ThemeUtils.resolveColor(getContext(), R.attr.gallery_page_bg, R.color.gallery_default_page_bg);
    mRlRootView.setBackgroundColor(pageColor);
}
项目:Watermark    文件:MediaPreviewFragment.java   
@Override
public void setTheme() {
    super.setTheme();
    int checkTint = ThemeUtils.resolveColor(getContext(), R.attr.gallery_checkbox_button_tint_color, R.color.gallery_default_checkbox_button_tint_color);
    CompoundButtonCompat.setButtonTintList(mCbCheck, ColorStateList.valueOf(checkTint));
    int cbTextColor = ThemeUtils.resolveColor(getContext(), R.attr.gallery_checkbox_text_color, R.color.gallery_default_checkbox_text_color);
    mCbCheck.setTextColor(cbTextColor);

    int pageColor = ThemeUtils.resolveColor(getContext(), R.attr.gallery_page_bg, R.color.gallery_default_page_bg);
    mRlRootView.setBackgroundColor(pageColor);
}
项目:Watermark    文件:BucketAdapter.java   
BucketViewHolder(ViewGroup parent, View itemView) {
    super(itemView);
    this.mParentView = parent;
    mTvBucketName = (TextView) itemView.findViewById(R.id.tv_bucket_name);
    mIvBucketCover = (SquareImageView) itemView.findViewById(R.id.iv_bucket_cover);
    mRbSelected = (AppCompatRadioButton) itemView.findViewById(R.id.rb_selected);

    itemView.setOnClickListener(this);

    int checkTint = ThemeUtils.resolveColor(itemView.getContext(), R.attr.gallery_checkbox_button_tint_color, R.color.gallery_default_checkbox_button_tint_color);
    CompoundButtonCompat.setButtonTintList(mRbSelected, ColorStateList.valueOf(checkTint));
}
项目:Watermark    文件:MediaGridAdapter.java   
GridViewHolder(View itemView) {
    super(itemView);
    mIvMediaImage = itemView.findViewById(R.id.iv_media_image);
    mCbCheck = (AppCompatCheckBox) itemView.findViewById(R.id.cb_check);
    relativeLayout = (SquareRelativeLayout) itemView.findViewById(R.id.rootView);
    mLlCamera = (LinearLayout) itemView.findViewById(R.id.ll_camera);
    mTvCameraTxt = (TextView) itemView.findViewById(R.id.tv_camera_txt);
    mIvCameraImage = (ImageView) itemView.findViewById(R.id.iv_camera_image);

    int checkTint = ThemeUtils.resolveColor(itemView.getContext(), R.attr.gallery_checkbox_button_tint_color, R.color.gallery_default_checkbox_button_tint_color);
    CompoundButtonCompat.setButtonTintList(mCbCheck, ColorStateList.valueOf(checkTint));
}
项目:revolution-irc    文件:ThemedCheckBox.java   
public static void install(CompoundButton checkBox, AttributeSet attrs) {
    ThemedView.setupBackground(checkBox, attrs);
    if (ThemeHelper.hasCustomAccentColor(checkBox.getContext())) {
        CompoundButtonCompat.setButtonTintList(checkBox,
                createCheckBoxTintStateList(checkBox.getContext()));
        if (Build.VERSION.SDK_INT >= 21 && checkBox.getBackground() instanceof RippleDrawable) {
            ((RippleDrawable) checkBox.getBackground()).setColor(
                    createCheckBoxRippleTintStateList(checkBox.getContext()));
        }
    }
}
项目:boohee_v5.6    文件:AppCompatCompoundButtonHelper.java   
int getCompoundPaddingLeft(int superValue) {
    if (VERSION.SDK_INT >= 17) {
        return superValue;
    }
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(this.mView);
    if (buttonDrawable != null) {
        return superValue + buttonDrawable.getIntrinsicWidth();
    }
    return superValue;
}
项目:Android-skin-support    文件:SkinCompatCompoundButtonHelper.java   
@Override
public void applySkin() {
    mButtonResourceId = SkinCompatHelper.checkResourceId(mButtonResourceId);
    if (mButtonResourceId != INVALID_ID) {
        mView.setButtonDrawable(SkinCompatResources.getDrawableCompat(mView.getContext(), mButtonResourceId));
    }
    mButtonTintResId = SkinCompatHelper.checkResourceId(mButtonTintResId);
    if (mButtonTintResId != INVALID_ID) {
        CompoundButtonCompat.setButtonTintList(mView, SkinCompatResources.getColorStateList(mView.getContext(), mButtonTintResId));
    }
}
项目:MagicaSakura    文件:TintRadioButton.java   
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}
项目:MagicaSakura    文件:AppCompatCompoundButtonHelper.java   
public int getCompoundPaddingLeft(int superValue) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // Before JB-MR1 the button drawable wasn't taken into account for padding. We'll
        // workaround that here
        Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView);
        if (buttonDrawable != null) {
            superValue += buttonDrawable.getIntrinsicWidth();
        }
    }
    return superValue;
}
项目:MagicaSakura    文件:TintCheckBox.java   
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}
项目:MagicaSakura    文件:TintSwitchCompat.java   
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}
项目:FMTech    文件:AppCompatCompoundButtonHelper.java   
final int getCompoundPaddingLeft(int paramInt)
{
  if (Build.VERSION.SDK_INT < 17)
  {
    Drawable localDrawable = CompoundButtonCompat.getButtonDrawable(this.mView);
    if (localDrawable != null) {
      paramInt += localDrawable.getIntrinsicWidth();
    }
  }
  return paramInt;
}
项目:MyCTFWriteUps    文件:AppCompatCompoundButtonHelper.java   
int getCompoundPaddingLeft(int i)
{
    int j = i;
    if (android.os.Build.VERSION.SDK_INT < 17)
    {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(mView);
        j = i;
        if (drawable != null)
        {
            j = i + drawable.getIntrinsicWidth();
        }
    }
    return j;
}
项目:underlx    文件:AnnouncementsIntroSlide.java   
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_intro_announcements, container, false);

    ((Button) view.findViewById(R.id.select_sources_button)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            view.findViewById(R.id.description_layout).setVisibility(View.GONE);
            view.findViewById(R.id.select_sources_button).setVisibility(View.GONE);

            LinearLayout checkboxLayout = (LinearLayout) view.findViewById(R.id.checkbox_layout);

            SharedPreferences sharedPref = getContext().getSharedPreferences("notifsettings", Context.MODE_PRIVATE);
            Set<String> sourcePref = sharedPref.getStringSet("pref_notifs_announcement_sources", null);

            for (final Announcement.Source s : Announcement.getSources()) {
                AppCompatCheckBox checkBox = new AppCompatCheckBox(view.getContext());
                checkBox.setText(getString(s.nameResourceId));
                checkBox.setTextColor(Color.WHITE);
                ColorStateList colorStateList = new ColorStateList(
                        new int[][]{
                                new int[]{-android.R.attr.state_checked}, // unchecked
                                new int[]{android.R.attr.state_checked}, // checked
                        },
                        new int[]{s.color, s.color,}
                );
                CompoundButtonCompat.setButtonTintList(checkBox, colorStateList);

                checkBox.setChecked(sourcePref == null || sourcePref.contains(s.id));

                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        updateShowAnnouncementNotifs(s.id, isChecked);
                    }
                });

                checkboxLayout.addView(checkBox);
            }

            view.findViewById(R.id.sources_layout).setVisibility(View.VISIBLE);
        }
    });

    return view;
}
项目:underlx    文件:DisturbancesIntroSlide.java   
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_intro_disturbances, container, false);

    ((Button) view.findViewById(R.id.select_lines_button)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            List<Line> lines = new LinkedList<>();
            if (mListener != null && mListener.getMainService() != null) {
                for (Network n : mListener.getMainService().getNetworks()) {
                    lines.addAll(n.getLines());
                }
                Collections.sort(lines, new Comparator<Line>() {
                    @Override
                    public int compare(Line line, Line t1) {
                        return line.getName().compareTo(t1.getName());
                    }
                });
            }

            if (lines.size() == 0) {
                if (Connectivity.isConnected(getContext())) {
                    Snackbar.make(view, R.string.intro_disturbances_misc_error, Snackbar.LENGTH_LONG).show();
                } else {
                    Snackbar.make(view, R.string.intro_disturbances_connection_error, Snackbar.LENGTH_LONG).show();
                }
                return;
            }
            view.findViewById(R.id.description_layout).setVisibility(View.GONE);
            view.findViewById(R.id.select_lines_button).setVisibility(View.GONE);

            LinearLayout checkboxLayout = (LinearLayout) view.findViewById(R.id.checkbox_layout);

            SharedPreferences sharedPref = getContext().getSharedPreferences("notifsettings", Context.MODE_PRIVATE);
            Set<String> linePref = sharedPref.getStringSet("pref_notifs_lines", null);

            for (final Line l : lines) {
                AppCompatCheckBox checkBox = new AppCompatCheckBox(view.getContext());
                checkBox.setText(l.getName());
                checkBox.setTextColor(Color.WHITE);
                ColorStateList colorStateList = new ColorStateList(
                        new int[][]{
                                new int[]{-android.R.attr.state_checked}, // unchecked
                                new int[]{android.R.attr.state_checked}, // checked
                        },
                        new int[]{l.getColor(), l.getColor(),}
                );
                CompoundButtonCompat.setButtonTintList(checkBox, colorStateList);

                checkBox.setChecked(linePref == null || linePref.contains(l.getId()));

                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        updateShowLineNotifs(l.getId(), isChecked);
                    }
                });

                checkboxLayout.addView(checkBox);
            }

            view.findViewById(R.id.lines_layout).setVisibility(View.VISIBLE);
        }
    });

    return view;
}
项目:ToggleButtons    文件:ToggleButton.java   
@Override
protected void onDraw(Canvas canvas) {
    // If there's text of any sort resort to CompoundButton#onDraw
    if (getText() != null && getText().length() > 0 ||
        getTextOff() != null && getTextOff().length() > 0 ||
        getTextOff() != null && getTextOn().length() > 0) {
        super.onDraw(canvas);
    }
    // Otherwise override CompoundButton#onDraw entirely to allow properly aligned image toggles
    else {
        final Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(this);
        if (buttonDrawable != null) {
            final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
            final int horizontalGravity = getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK;
            final int drawableHeight = buttonDrawable.getIntrinsicHeight();
            final int drawableWidth = buttonDrawable.getIntrinsicWidth();

            final int top;
            switch (verticalGravity) {
                case Gravity.BOTTOM:
                    top = getHeight() - drawableHeight;
                    break;
                case Gravity.CENTER_VERTICAL:
                    top = (getHeight() - drawableHeight) / 2;
                    break;
                default:
                    top = 0;
            }

            final int left;
            switch (horizontalGravity) {
                case Gravity.RIGHT:
                case Gravity.END:
                    left = getWidth() - drawableWidth;
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    left = (getWidth() - drawableWidth) / 2;
                    break;
                default:
                    left = 0;
            }

            final int bottom = top + drawableHeight;
            final int right = left + drawableWidth;

            buttonDrawable.setBounds(left, top, right, bottom);

            final Drawable background = getBackground();
            if (Build.VERSION.SDK_INT > 21 && background != null) {
                background.setHotspotBounds(left, top, right, bottom);
            }

            buttonDrawable.draw(canvas);
        }
    }
}
项目:Red-Calorie    文件:TagItemHolder.java   
public void setCheckedTint(@ColorInt int color) {
    CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(color));
}
项目:introduction    文件:IntroductionFragment.java   
@NonNull
private View initDefaultViews(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.introduction_fragment_content, container, false);
    ViewGroup descriptionContainer = root.findViewById(R.id.introduction_fragment_content_description_container);

    TextView title = root.findViewById(R.id.introduction_fragment_content_title);
    ImageView image = root.findViewById(R.id.introduction_fragment_content_image);
    TextView description = null;

    if (slide.getTitle() != null) {
        title.setText(slide.getTitle());
        title.setMaxLines(getLineCountForTitle());
        title.setTypeface(IntroductionConfiguration.getInstance().getTitleTypeface());

        if (slide.getTitleSize() != null) {
            title.setTextSize(COMPLEX_UNIT_DIP, slide.getTitleSize());
        }
    } else {
        title.setVisibility(GONE);
        title = null;
    }

    if (slide.getDescription() == null && slide.getOption() != null) {
        ColorStateList buttonColors = ContextCompat.getColorStateList(getSafeContext(), android.R.color.white);
        CheckBox option = (CheckBox) inflater.inflate(R.layout.introduction_fragment_option,
                descriptionContainer, false);

        option.setText(slide.getOption().getTitle());
        option.setChecked(slide.getOption().isActivated());
        option.setOnCheckedChangeListener((buttonView, isChecked) -> slide.getOption().setActivated(isChecked));

        CompoundButtonCompat.setButtonTintList(option, buttonColors);

        descriptionContainer.addView(option);
        description = option;
    } else if (slide.getDescription() != null) {
        description = (TextView) inflater.inflate(R.layout.introduction_fragment_description,
                descriptionContainer, false);

        description.setText(slide.getDescription());
        descriptionContainer.addView(description);
    } else {
        descriptionContainer.setVisibility(GONE);
    }

    if (description != null) {
        description.setMaxLines(getLineCountForDescription());
        description.setTypeface(IntroductionConfiguration.getInstance().getDescriptionTypeface());

        if (slide.getDescriptionSize() != null) {
            description.setTextSize(COMPLEX_UNIT_DIP, slide.getDescriptionSize());
        }
    }

    if (slide.getImageResource() != null) {
        image.setImageResource(slide.getImageResource());
    }

    IntroductionConfiguration.getInstance().callOnSlideInit(slide.getPosition(), title, image, description);

    return root;
}