Java Code Examples for androidx.core.view.ViewCompat#setPaddingRelative()

The following examples show how to use androidx.core.view.ViewCompat#setPaddingRelative() . 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: TabLayout.java    From a with GNU General Public License v3.0 6 votes vote down vote up
private void applyModeAndGravity() {
    int paddingStart = 0;
    if (mMode == MODE_SCROLLABLE) {
        // If we're scrollable, or fixed at start, inset using padding
        paddingStart = Math.max(0, mContentInsetStart - mTabPaddingStart);
    }
    ViewCompat.setPaddingRelative(mTabStrip, paddingStart, 0, 0, 0);

    switch (mMode) {
        case MODE_FIXED:
            mTabStrip.setGravity(Gravity.CENTER_HORIZONTAL);
            break;
        case MODE_SCROLLABLE:
            mTabStrip.setGravity(GravityCompat.START);
            break;
    }

    updateTabViews(true);
}
 
Example 2
Source File: TabLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void applyModeAndGravity() {
  int paddingStart = 0;
  if (mode == MODE_SCROLLABLE || mode == MODE_AUTO) {
    // If we're scrollable, or fixed at start, inset using padding
    paddingStart = Math.max(0, contentInsetStart - tabPaddingStart);
  }
  ViewCompat.setPaddingRelative(slidingTabIndicator, paddingStart, 0, 0, 0);

  switch (mode) {
    case MODE_AUTO:
    case MODE_FIXED:
      if (tabGravity == GRAVITY_START) {
        Log.w(
            LOG_TAG,
            "GRAVITY_START is not supported with the current tab mode, GRAVITY_CENTER will be"
                + " used instead");
      }
      slidingTabIndicator.setGravity(Gravity.CENTER_HORIZONTAL);
      break;
    case MODE_SCROLLABLE:
      applyGravityForModeScrollable(tabGravity);
      break;
  }

  updateTabViews(true);
}
 
Example 3
Source File: Chip.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the paddings to inform {@link android.widget.TextView} how much width the text can
 * occupy.
 */
private void updatePaddingInternal() {
  if (TextUtils.isEmpty(getText()) || chipDrawable == null) {
    return;
  }
  int paddingEnd =
      (int)
          (chipDrawable.getChipEndPadding()
              + chipDrawable.getTextEndPadding()
              + chipDrawable.calculateCloseIconWidth());
  int paddingStart =
      (int)
          (chipDrawable.getChipStartPadding()
              + chipDrawable.getTextStartPadding()
              + chipDrawable.calculateChipIconWidth());
  if (insetBackgroundDrawable != null) {
    Rect padding = new Rect();
    insetBackgroundDrawable.getPadding(padding);
    paddingStart += padding.left;
    paddingEnd += padding.right;
  }

  ViewCompat.setPaddingRelative(
      this, paddingStart, getPaddingTop(), paddingEnd, getPaddingBottom());
}
 
Example 4
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 6 votes vote down vote up
/**
 * Adapts the width of the navigation.
 */
private void adaptNavigationWidth() {
    if (frameLayout != null && navigationFragmentContainer != null && cardView != null &&
            toolbarLarge != null) {
        ViewCompat.setPaddingRelative(navigationFragmentContainer, 0, 0,
                getDisplayWidth(this) - navigationWidth, 0);

        if (!isNavigationHidden()) {
            toolbarLarge.setNavigationWidth(navigationWidth);
            FrameLayout.LayoutParams cardViewLayoutParams =
                    (FrameLayout.LayoutParams) cardView.getLayoutParams();
            int margin = navigationWidth -
                    getResources().getDimensionPixelSize(R.dimen.card_view_intrinsic_margin);
            setMarginStart(cardViewLayoutParams, margin);
        }
    }
}
 
Example 5
Source File: CorrectedPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void setZeroPaddingToLayoutChildren(View view) {
  if (!(view instanceof ViewGroup)) return;

  ViewGroup viewGroup = (ViewGroup) view;
  for (int i = 0; i < viewGroup.getChildCount(); i++) {
    setZeroPaddingToLayoutChildren(viewGroup.getChildAt(i));
    ViewCompat.setPaddingRelative(viewGroup, 0, viewGroup.getPaddingTop(), ViewCompat.getPaddingEnd(viewGroup), viewGroup.getPaddingBottom());
  }
}
 
Example 6
Source File: TabLayout.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public TabView(Context context) {
    super(context);
    if (mTabBackgroundResId != 0) {
        ViewCompat.setBackground(
                this, AppCompatResources.getDrawable(context, mTabBackgroundResId));
    }
    ViewCompat.setPaddingRelative(this, mTabPaddingStart, mTabPaddingTop,
            mTabPaddingEnd, mTabPaddingBottom);
    setGravity(Gravity.CENTER);
    setOrientation(VERTICAL);
    setClickable(true);
    ViewCompat.setPointerIcon(this,
            PointerIconCompat.getSystemIcon(getContext(), PointerIconCompat.TYPE_HAND));
}
 
Example 7
Source File: CustomTextInputLayout.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public void setHelperTextEnabled(boolean enabled) {
  if (helperTextEnabled == enabled) {
    return;
  }
  if (enabled && errorEnabled) {
    setErrorEnabled(false);
  }
  if (this.helperTextEnabled != enabled) {
    if (enabled) {
      this.helperView = new TextView(this.getContext());
      this.helperView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
      this.helperView.setTextAppearance(this.getContext(), this.helperTextAppearance);
      if (helperTextColor != null) {
        this.helperView.setTextColor(helperTextColor);
      }
      this.helperView.setText(helperText);
      this.helperView.setVisibility(VISIBLE);
      this.addView(this.helperView);
      if (this.helperView != null && getEditText() != null) {
        ViewCompat.setPaddingRelative(this.helperView, ViewCompat.getPaddingStart(getEditText()),
            0, ViewCompat.getPaddingEnd(getEditText()), getEditText().getPaddingBottom());
      }
    } else {
      this.removeView(this.helperView);
      this.helperView = null;
    }
    this.helperTextEnabled = enabled;
  }
}
 
Example 8
Source File: SnackbarContentLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private static void updateTopBottomPadding(
    @NonNull View view, int topPadding, int bottomPadding) {
  if (ViewCompat.isPaddingRelative(view)) {
    ViewCompat.setPaddingRelative(
        view,
        ViewCompat.getPaddingStart(view),
        topPadding,
        ViewCompat.getPaddingEnd(view),
        bottomPadding);
  } else {
    view.setPadding(view.getPaddingLeft(), topPadding, view.getPaddingRight(), bottomPadding);
  }
}
 
Example 9
Source File: TabLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public TabView(@NonNull Context context) {
  super(context);
  updateBackgroundDrawable(context);
  ViewCompat.setPaddingRelative(
      this, tabPaddingStart, tabPaddingTop, tabPaddingEnd, tabPaddingBottom);
  setGravity(Gravity.CENTER);
  setOrientation(inlineLabel ? HORIZONTAL : VERTICAL);
  setClickable(true);
  ViewCompat.setPointerIcon(
      this, PointerIconCompat.getSystemIcon(getContext(), PointerIconCompat.TYPE_HAND));
}
 
Example 10
Source File: IndicatorViewController.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
void adjustIndicatorPadding() {
  if (canAdjustIndicatorPadding()) {
    // Add padding to the indicators so that they match the EditText
    ViewCompat.setPaddingRelative(
        indicatorArea,
        ViewCompat.getPaddingStart(textInputView.getEditText()),
        0,
        ViewCompat.getPaddingEnd(textInputView.getEditText()),
        0);
  }
}
 
Example 11
Source File: TSnackbar.java    From TSnackBar with Apache License 2.0 5 votes vote down vote up
private static void updateTopBottomPadding(View view, int topPadding, int bottomPadding) {
    if (ViewCompat.isPaddingRelative(view)) {
        ViewCompat.setPaddingRelative(view,
                ViewCompat.getPaddingStart(view), topPadding,
                ViewCompat.getPaddingEnd(view), bottomPadding);
    } else {
        view.setPadding(view.getPaddingLeft(), topPadding,
                view.getPaddingRight(), bottomPadding);
    }
}
 
Example 12
Source File: SmartTabLayout.java    From SmartTabLayout with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);
  if (tabStrip.isIndicatorAlwaysInCenter() && tabStrip.getChildCount() > 0) {
    View firstTab = tabStrip.getChildAt(0);
    View lastTab = tabStrip.getChildAt(tabStrip.getChildCount() - 1);
    int start = (w - Utils.getMeasuredWidth(firstTab)) / 2 - Utils.getMarginStart(firstTab);
    int end = (w - Utils.getMeasuredWidth(lastTab)) / 2 - Utils.getMarginEnd(lastTab);
    tabStrip.setMinimumWidth(tabStrip.getMeasuredWidth());
    ViewCompat.setPaddingRelative(this, start, getPaddingTop(), end, getPaddingBottom());
    setClipToPadding(false);
  }
}
 
Example 13
Source File: RecyclerSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) boolean hasFixedSize,
    @Prop(optional = true) boolean clipToPadding,
    @Prop(optional = true) int leftPadding,
    @Prop(optional = true) int rightPadding,
    @Prop(optional = true) int topPadding,
    @Prop(optional = true) int bottomPadding,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) int refreshProgressBarColor,
    @Prop(optional = true) boolean clipChildren,
    @Prop(optional = true) boolean nestedScrollingEnabled,
    @Prop(optional = true) int scrollBarStyle,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true) boolean horizontalFadingEdgeEnabled,
    @Prop(optional = true) boolean verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) int fadingEdgeLength,
    @Prop(optional = true) @IdRes int recyclerViewId,
    @Prop(optional = true) int overScrollMode,
    @Prop(optional = true, isCommonProp = true) CharSequence contentDescription,
    @Prop(optional = true) ItemAnimator itemAnimator) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout");
  }
  recyclerView.setContentDescription(contentDescription);
  recyclerView.setHasFixedSize(hasFixedSize);
  recyclerView.setClipToPadding(clipToPadding);
  sectionsRecycler.setClipToPadding(clipToPadding);
  ViewCompat.setPaddingRelative(
      recyclerView, leftPadding, topPadding, rightPadding, bottomPadding);
  recyclerView.setClipChildren(clipChildren);
  sectionsRecycler.setClipChildren(clipChildren);
  recyclerView.setNestedScrollingEnabled(nestedScrollingEnabled);
  sectionsRecycler.setNestedScrollingEnabled(nestedScrollingEnabled);
  recyclerView.setScrollBarStyle(scrollBarStyle);
  recyclerView.setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled);
  recyclerView.setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled);
  recyclerView.setFadingEdgeLength(fadingEdgeLength);
  // TODO (t14949498) determine if this is necessary
  recyclerView.setId(recyclerViewId);
  recyclerView.setOverScrollMode(overScrollMode);
  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(refreshProgressBarBackgroundColor);
  }
  sectionsRecycler.setColorSchemeColors(refreshProgressBarColor);

  if (itemDecoration != null) {
    recyclerView.addItemDecoration(itemDecoration);
  }

  sectionsRecycler.setItemAnimator(
      itemAnimator != RecyclerSpec.itemAnimator ? itemAnimator : new NoUpdateItemAnimator());

  binder.mount(recyclerView);
}
 
Example 14
Source File: MaterialButtonHelper.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
void loadFromAttributes(@NonNull TypedArray attributes) {
  insetLeft = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetLeft, 0);
  insetRight =
      attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetRight, 0);
  insetTop = attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetTop, 0);
  insetBottom =
      attributes.getDimensionPixelOffset(R.styleable.MaterialButton_android_insetBottom, 0);

  // cornerRadius should override whatever corner radius is set in shapeAppearanceModel
  if (attributes.hasValue(R.styleable.MaterialButton_cornerRadius)) {
    cornerRadius = attributes.getDimensionPixelSize(R.styleable.MaterialButton_cornerRadius, -1);
    setShapeAppearanceModel(shapeAppearanceModel.withCornerSize(cornerRadius));
    cornerRadiusSet = true;
  }

  strokeWidth = attributes.getDimensionPixelSize(R.styleable.MaterialButton_strokeWidth, 0);

  backgroundTintMode =
      ViewUtils.parseTintMode(
          attributes.getInt(R.styleable.MaterialButton_backgroundTintMode, -1), Mode.SRC_IN);
  backgroundTint =
      MaterialResources.getColorStateList(
          materialButton.getContext(), attributes, R.styleable.MaterialButton_backgroundTint);
  strokeColor =
      MaterialResources.getColorStateList(
          materialButton.getContext(), attributes, R.styleable.MaterialButton_strokeColor);
  rippleColor =
      MaterialResources.getColorStateList(
          materialButton.getContext(), attributes, R.styleable.MaterialButton_rippleColor);

  checkable = attributes.getBoolean(R.styleable.MaterialButton_android_checkable, false);
  int elevation = attributes.getDimensionPixelSize(R.styleable.MaterialButton_elevation, 0);

  // Store padding before setting background, since background overwrites padding values
  int paddingStart = ViewCompat.getPaddingStart(materialButton);
  int paddingTop = materialButton.getPaddingTop();
  int paddingEnd = ViewCompat.getPaddingEnd(materialButton);
  int paddingBottom = materialButton.getPaddingBottom();

  // Update materialButton's background without triggering setBackgroundOverwritten()
  if (attributes.hasValue(R.styleable.MaterialButton_android_background)) {
    setBackgroundOverwritten();
  } else {
    materialButton.setInternalBackground(createBackground());
    MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable();
    if (materialShapeDrawable != null) {
      materialShapeDrawable.setElevation(elevation);
    }
  }
  // Set the stored padding values
  ViewCompat.setPaddingRelative(
      materialButton,
      paddingStart + insetLeft,
      paddingTop + insetTop,
      paddingEnd + insetRight,
      paddingBottom + insetBottom);
}
 
Example 15
Source File: ViewUtils.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
/** Applies this relative padding to the view. */
public void applyToView(View view) {
  ViewCompat.setPaddingRelative(view, start, top, end, bottom);
}
 
Example 16
Source File: DiscussionTopicsAdapter.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
@Override
public void render(BaseViewHolder tag, DiscussionTopicDepth discussionTopic) {
    ViewHolder holder = (ViewHolder) tag;
    holder.discussionTopicNameTextView.setText(discussionTopic.getDiscussionTopic().getName());
    ViewCompat.setPaddingRelative(holder.discussionTopicNameTextView, childPadding * (1 + discussionTopic.getDepth()), childPadding, childPadding, childPadding);
}