Java Code Examples for androidx.core.graphics.drawable.DrawableCompat#setLayoutDirection()

The following examples show how to use androidx.core.graphics.drawable.DrawableCompat#setLayoutDirection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubtitleCollapsingToolbarLayout.java    From collapsingtoolbarlayout-subtitle with Apache License 2.0 6 votes vote down vote up
/**
 * Set the drawable to use for the status bar scrim from resources. Providing null will disable
 * the scrim functionality.
 * <p>
 * <p>This scrim is only shown when we have been given a top system inset.
 *
 * @param drawable the drawable to display
 * @attr ref R.styleable#SubtitleCollapsingToolbarLayout_statusBarScrim
 * @see #getStatusBarScrim()
 */
public void setStatusBarScrim(@Nullable Drawable drawable) {
    if (statusBarScrim != drawable) {
        if (statusBarScrim != null) {
            statusBarScrim.setCallback(null);
        }
        statusBarScrim = drawable != null ? drawable.mutate() : null;
        if (statusBarScrim != null) {
            if (statusBarScrim.isStateful()) {
                statusBarScrim.setState(getDrawableState());
            }
            DrawableCompat.setLayoutDirection(statusBarScrim, ViewCompat.getLayoutDirection(this));
            statusBarScrim.setVisible(getVisibility() == VISIBLE, false);
            statusBarScrim.setCallback(this);
            statusBarScrim.setAlpha(scrimAlpha);
        }
        ViewCompat.postInvalidateOnAnimation(this);
    }
}
 
Example 2
Source File: CollapsingTitleBarLayout.java    From UIWidget with Apache License 2.0 6 votes vote down vote up
/**
 * Set the drawable to use for the status bar scrim from resources.
 * Providing null will disable the scrim functionality.
 * <p>
 * <p>This scrim is only shown when we have been given a top system inset.</p>
 *
 * @param drawable the drawable to display
 * @see #getStatusBarScrim()
 */
public CollapsingTitleBarLayout setStatusBarScrim(@Nullable Drawable drawable) {
    if (mStatusBarScrim != drawable) {
        if (mStatusBarScrim != null) {
            mStatusBarScrim.setCallback(null);
        }
        mStatusBarScrim = drawable != null ? drawable.mutate() : null;
        if (mStatusBarScrim != null) {
            if (mStatusBarScrim.isStateful()) {
                mStatusBarScrim.setState(getDrawableState());
            }
            DrawableCompat.setLayoutDirection(mStatusBarScrim,
                    ViewCompat.getLayoutDirection(this));
            mStatusBarScrim.setVisible(getVisibility() == VISIBLE, false);
            mStatusBarScrim.setCallback(this);
            mStatusBarScrim.setAlpha(mScrimAlpha);
        }
        ViewCompat.postInvalidateOnAnimation(this);
    }
    return this;
}
 
Example 3
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Set the drawable to use for the status bar foreground drawable. Providing null will disable the
 * scrim functionality.
 *
 * <p>This scrim is only shown when we have been given a top system inset.
 *
 * @param drawable the drawable to display
 * @attr ref R.styleable#AppBarLayout_statusBarForeground
 * @see #getStatusBarForeground()
 */
public void setStatusBarForeground(@Nullable Drawable drawable) {
  if (statusBarForeground != drawable) {
    if (statusBarForeground != null) {
      statusBarForeground.setCallback(null);
    }
    statusBarForeground = drawable != null ? drawable.mutate() : null;
    if (statusBarForeground != null) {
      if (statusBarForeground.isStateful()) {
        statusBarForeground.setState(getDrawableState());
      }
      DrawableCompat.setLayoutDirection(statusBarForeground, ViewCompat.getLayoutDirection(this));
      statusBarForeground.setVisible(getVisibility() == VISIBLE, false);
      statusBarForeground.setCallback(this);
    }
    updateWillNotDraw();
    ViewCompat.postInvalidateOnAnimation(this);
  }
}
 
Example 4
Source File: CollapsingToolbarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Set the drawable to use for the status bar scrim from resources. Providing null will disable
 * the scrim functionality.
 *
 * <p>This scrim is only shown when we have been given a top system inset.
 *
 * @param drawable the drawable to display
 * @attr ref R.styleable#CollapsingToolbarLayout_statusBarScrim
 * @see #getStatusBarScrim()
 */
public void setStatusBarScrim(@Nullable Drawable drawable) {
  if (statusBarScrim != drawable) {
    if (statusBarScrim != null) {
      statusBarScrim.setCallback(null);
    }
    statusBarScrim = drawable != null ? drawable.mutate() : null;
    if (statusBarScrim != null) {
      if (statusBarScrim.isStateful()) {
        statusBarScrim.setState(getDrawableState());
      }
      DrawableCompat.setLayoutDirection(statusBarScrim, ViewCompat.getLayoutDirection(this));
      statusBarScrim.setVisible(getVisibility() == VISIBLE, false);
      statusBarScrim.setCallback(this);
      statusBarScrim.setAlpha(scrimAlpha);
    }
    ViewCompat.postInvalidateOnAnimation(this);
  }
}
 
Example 5
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLayoutDirectionChanged(int layoutDirection) {
  boolean invalidate = super.onLayoutDirectionChanged(layoutDirection);

  if (showsChipIcon()) {
    invalidate |= DrawableCompat.setLayoutDirection(chipIcon, layoutDirection);
  }
  if (showsCheckedIcon()) {
    invalidate |= DrawableCompat.setLayoutDirection(checkedIcon, layoutDirection);
  }
  if (showsCloseIcon()) {
    invalidate |= DrawableCompat.setLayoutDirection(closeIcon, layoutDirection);
  }

  if (invalidate) {
    invalidateSelf();
  }
  return true;
}
 
Example 6
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Note: This should not change the size of the drawable. */
private void applyChildDrawable(@Nullable Drawable drawable) {
  if (drawable == null) {
    return;
  }
  drawable.setCallback(this);
  DrawableCompat.setLayoutDirection(drawable, DrawableCompat.getLayoutDirection(this));
  drawable.setLevel(getLevel());
  drawable.setVisible(isVisible(), false);

  if (drawable == closeIcon) {
    if (drawable.isStateful()) {
      drawable.setState(getCloseIconState());
    }
    DrawableCompat.setTintList(drawable, closeIconTint);
    return;
  }
  if (drawable.isStateful()) {
    drawable.setState(getState());
  }
  if (drawable == chipIcon && hasChipIconTint) {
    DrawableCompat.setTintList(chipIcon, chipIconTint);
  }
}
 
Example 7
Source File: RangeProgressBar.java    From RangeSeekBar with MIT License 5 votes vote down vote up
public void setProgressDrawable(Drawable d) {
    if (mProgressDrawable != d) {
        if (mProgressDrawable != null) {
            mProgressDrawable.setCallback(null);
            unscheduleDrawable(mProgressDrawable);
        }

        mProgressDrawable = d;

        if (d != null) {
            d.setCallback(this);
            DrawableCompat.setLayoutDirection(d, getLayoutDirection());
            if (d.isStateful()) {
                d.setState(getDrawableState());
            }

            // Make sure the ProgressBar is always tall enough
            int drawableHeight = d.getMinimumHeight();
            if (mMaxHeight < drawableHeight) {
                mMaxHeight = drawableHeight;
                requestLayout();
            }

            applyProgressTints();
        }

        swapCurrentDrawable(d);
        postInvalidate();

        updateDrawableBounds(getWidth(), getHeight());
        updateDrawableState();

        doRefreshProgress(android.R.id.progress, mStartProgress, mEndProgress, false, false, false);
    }
}
 
Example 8
Source File: RangeSeekBar.java    From RangeSeekBar with MIT License 4 votes vote down vote up
/**
 * Sets the thumb that will be drawn at the end of the progress meter within the SeekBar.
 * <p>
 * If the thumb is a valid drawable (i.e. not null), half its width will be
 * used as the new thumb offset (@see #setThumbOffset(int)).
 *
 * @param thumb Drawable representing the thumb
 * @param which which thumb
 */
public void setThumb(Drawable thumb, WhichThumb which) {
    final boolean needUpdate;

    Drawable whichThumb = which == WhichThumb.Start ? mThumbStart : mThumbEnd;

    if (whichThumb != null && thumb != whichThumb) {
        whichThumb.setCallback(null);
        needUpdate = true;
    } else {
        needUpdate = false;
    }

    if (thumb != null) {
        thumb.setCallback(this);
        DrawableCompat.setLayoutDirection(thumb, ViewCompat.getLayoutDirection(this));
        mThumbOffset = thumb.getIntrinsicWidth() / 2;
        mThumbWidth = thumb.getIntrinsicWidth();
        mThumbHeight = thumb.getIntrinsicHeight();

        if (needUpdate &&
            (thumb.getIntrinsicWidth() != whichThumb.getIntrinsicWidth()
                || thumb.getIntrinsicHeight() != whichThumb.getIntrinsicHeight())) {
            requestLayout();
        }
    }

    if (which == WhichThumb.Start) {
        mThumbStart = thumb;
    } else {
        mThumbEnd = thumb;
    }

    applyThumbTintInternal(which);
    invalidate();

    if (needUpdate) {
        updateThumbAndTrackPos(getWidth(), getHeight());
        if (thumb != null && thumb.isStateful()) {
            // Note that if the states are different this won't work.
            // For now, let's consider that an app bug.
            int[] state = getDrawableState();
            thumb.setState(state);
        }
    }
}