Java 类android.support.v4.view.TintableBackgroundView 实例源码

项目:MusicX-music-player    文件:TintHelper.java   
public static void setTint(@NonNull EditText editText, @ColorInt int color, boolean useDarker) {
    final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused},
            new int[]{}
    }, new int[]{
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light),
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
            color
    });
    if (editText instanceof TintableBackgroundView) {
        ViewCompat.setBackgroundTintList(editText, editTextColorStateList);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        editText.setBackgroundTintList(editTextColorStateList);
    }
    setCursorTint(editText, color);
}
项目:app-theme-engine    文件:TintHelper.java   
public static void setTint(@NonNull EditText editText, @ColorInt int color, boolean useDarker) {
    final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused},
            new int[]{}
    }, new int[]{
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light),
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
            color
    });
    if (editText instanceof TintableBackgroundView) {
        ViewCompat.setBackgroundTintList(editText, editTextColorStateList);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        editText.setBackgroundTintList(editTextColorStateList);
    }
    setCursorTint(editText, color);
}
项目:CodeColors    文件:CcAppCompatDrawableWrapper.java   
@Override
public void setColorFilter(ColorFilter colorFilter) {
    // Check if we should enforce our inner tintList.
    if (mTintList != null) {
        Drawable rootDrawable = getRootDrawable(this);
        View view = getView(rootDrawable);

        if (isTintableBackground(view, rootDrawable)) {
            // TintableBackgroundViews store internal tintLists for known drawables.
            // Those tintLists can become outdated, if they contain attributes that are code-colors.
            // We make sure to store and enforce different tintList every time the code-colors change.
            ColorStateList tintList = ((TintableBackgroundView) view).getSupportBackgroundTintList();
            if (tintList == null) {
                ((TintableBackgroundView) view).setSupportBackgroundTintList(mTintList);
                return;
            }
        }
    }

    // We are not restoring our inner tintList.
    // Apply the color filter normally.
    super.setColorFilter(colorFilter);
}
项目:tenor-android-demo-search    文件:SearchSuggestionVH.java   
public void render(@Nullable final SearchSuggestionRVItem item,
                   @Nullable final OnClickListener listener) {
    if (!hasContext() || item == null) {
        return;
    }

    mItem = item;
    if (listener != null) {
        mListener = listener;
    }

    mSuggestionField.setText(item.getSuggestion());

    if (mSuggestionField instanceof TintableBackgroundView) {
        // "AppCompatTextView" and "com.android.support:appcompat-v7" are used, tint all states
        ViewCompat.setBackgroundTintList(mSuggestionField,
                new ColorStateList(STATES, new int[]{
                        AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
                        AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
        return;
    }

    // "com.android.support:appcompat-v7" is likely not being used, and thus "TextView" is used
    Drawable background = mSuggestionField.getBackground();
    if (background instanceof TintAwareDrawable) {
        // tint all states of the given drawable
        DrawableCompat.setTintList(background,
                new ColorStateList(STATES, new int[]{
                        AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
                        AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
        return;
    }

    // last option, tint only the background individually
    AbstractDrawableUtils.setDrawableTint(getContext(), background, item.getPlaceholder());
}
项目:CodeColors    文件:CcTintableBackgroundColorCallbackAdapter.java   
@Override
public boolean onAdd(View view, InflateAddResult<View> outResult) {
    if (view instanceof TintableBackgroundView) {
        ColorStateList backgroundTintList = ((TintableBackgroundView) view).getSupportBackgroundTintList();
        if (backgroundTintList instanceof CodeColor) {
            outResult.set(view);
            outResult.add(
                    (CodeColor) backgroundTintList,
                    new TintableBackgroundCallback(backgroundTintList));
            return true;
        }
    }
    return false;
}
项目:CodeColors    文件:CcTintableBackgroundColorCallbackAdapter.java   
private boolean refreshDrawableState(View view) {
    if (((TintableBackgroundView) view).getSupportBackgroundTintList() == mBackgroundTintList) {
        view.refreshDrawableState();
        return true;
    } else {
        return false;
    }
}
项目:CodeColors    文件:CcAppCompatDrawableWrapper.java   
protected void updateTintList() {
    if (mUpdateTintList) {
        mUpdateTintList = false;

        Drawable rootDrawable = getRootDrawable(this);
        View view = getView(rootDrawable);
        Context context = getContext(view);
        if (context != null) {
            AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get();
            // The context wrapper ensures that the manager doesn't reuse old tint lists.
            Context contextWrapper = new ContextWrapper(context);
            ColorStateList tintList = drawableManager.getTintList(contextWrapper, mState.mId);

            if (tintList != null && isTintableBackground(view, rootDrawable)) {
                ColorStateList viewTintList = ((TintableBackgroundView) view).getSupportBackgroundTintList();
                // TintableBackgroundViews store internal tintLists for known drawables.
                // Those tintLists can become outdated, if they contain attributes that are code-colors.
                // We make sure to store and enforce different tintList every time the code-colors change.
                if (viewTintList == null || viewTintList == mTintList) {
                    ((TintableBackgroundView) view).setSupportBackgroundTintList(tintList);
                }
                mTintList = tintList;
            } else {
                // If tint list is null, tintDrawable will still try to set color filters.
                CcTintManager.tintDrawable(context, tintList, mDrawable, mState.mId);
            }
        }
    }
}
项目:Locate-driver    文件:MainActivity.java   
private void updateUI() {
    ((Button) this.findViewById(R.id.running_button)).setText((running) ? getResources().getString(R.string.stop) : getResources().getString(R.string.start));
    ((TintableBackgroundView) (Button) this.findViewById(R.id.running_button)).setSupportBackgroundTintList(ColorStateList.valueOf(getResources().getColor((running) ? R.color.colorAccent : R.color.colorPrimary)));
    ((TintableBackgroundView) (Button) this.findViewById(R.id.send_button)).setSupportBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
}
项目:CodeColors    文件:CcAppCompatDrawableWrapper.java   
private static boolean isTintableBackground(View view, Drawable rootDrawable) {
    return view instanceof TintableBackgroundView && view.getBackground() == rootDrawable;
}